www.webdeveloper.com
Results 1 to 2 of 2

Thread: Inserting number between <a> tag of html page to be inserted in database

  1. #1
    Join Date
    Sep 2013
    Posts
    221

    Inserting number between <a> tag of html page to be inserted in database

    Insert number between <a> tag of html page(url is mention in code) to be inserted in database.
    I have used DOM Document to get the content of between <a> tag but now want to add the numbers between the tag of the whole page to be inserted in database.
    Below is the code:
    <?php

    ini_set( "display_errors", 0); //warning not to display
    $homepage = file_get_contents('http://justdial.com/Mumbai/Restaurants/ct-304085');

    $xml = '<a class="ctc jcn">Details i want to get</a>';
    $dom = new DOMDocument;
    $dom->loadHTML($homepage);
    $spans = $dom->getElementsByTagName('a');


    echo $span;

    foreach ($spans as $span) {
    if($span->getAttribute('class') == 'ctc f13') {

    $t=trim(strip_tags($span->nodeValue));
    echo $t;
    $con=mysqli_connect("localhost","root","","test");
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $sql="INSERT INTO justdailno (number) VALUES ('$t')";
    if (!mysqli_query($con,$sql))
    {
    die('Error: ' . mysqli_error($con));
    }
    echo "1 record added";

    mysqli_close($con);

    }
    }
    ?>
    can any one help me out with this....
    Thanks in advance.

  2. #2
    Join Date
    Sep 2013
    Posts
    221
    I solved my problem .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles