Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Confusion with preg_match for Specific DIV can anyone help me?

    Can anyone tell me how to fetch all data in specific DIV and inside it is specific Tag " <p></p>" of given url

    I Tried this but changing tag names but i Failed please any php expert can me help me ?

    <?php

    function getdata($Url){
    $str = file_get_contents($Url);
    if(strlen($str)>0){
    preg_match("/\<title\>(.*)\<\/title\>/",$str,$data);
    return $data[1];
    }
    }

    echo getdata("http://www.w3schools.com/");

    ?>



    Example URL : www.productsite.com


    Product Web HTML Example :

    <div class="products">
    <a href="productsite.com" class="title"><strong>Product 1</strong></a><br/>
    <p>http://www.productsite.com/simpleproducatpage1.aspx<br/></p>
    <br/>
    </div>
    <div class="products">
    <a href="productsite.com" class="title"><strong>Product 2</strong></a><br/>
    <p>http://www.productsite.com/simpleproducatpage2.aspx<br/></p>
    <br/>
    </div>
    <div class="products">
    <a href="productsite.com" class="title"><strong>Product 3</strong></a><br/>
    <p>http://www.productsite.com/simpleproducatpage3.aspx<br/></p>
    <br/>
    </div>
    <div class="products">
    <a href="productsite.com" class="title"><strong>Product 4</strong></a><br/>
    <p>http://www.productsite.com/simpleproducatpage4.aspx<br/></p>
    <br/>
    </div>
    <div class="products">
    <a href="productsite.com" class="title"><strong>Product 5</strong></a><br/>
    <p>http://www.productsite.com/simpleproducatpage5.aspx<br/></p>
    <br/>
    </div>
    <div class="products">
    <a href="productsite.com" class="title"><strong>Product 6</strong></a><br/>
    <p>http://www.productsite.com/simpleproducatpage6.aspx<br/></p>
    <br/>
    </div>
    <div class="products">
    <a href="productsite.com" class="title"><strong>Product 7</strong></a><br/>
    <p>http://www.productsite.com/simpleproducatpage7.aspx<br/></p>
    <br/>
    </div>
    and so on ...

    This Output i need :

    http://www.productsite.com/simpleproducatpage1.aspx
    http://www.productsite.com/simpleproducatpage2.aspx
    http://www.productsite.com/simpleproducatpage3.aspx
    http://www.productsite.com/simpleproducatpage4.aspx
    http://www.productsite.com/simpleproducatpage5.aspx
    http://www.productsite.com/simpleproducatpage6.aspx
    http://www.productsite.com/simpleproducatpage7.aspx
    and so on ...

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    240
    Thanks
    1
    Thanked 56 Times in 55 Posts
    PHP Code:
    $pattern '#<div class="products">.+?<p>(http://[^<]+)#si';
    if (
    preg_match_all($pattern$str$m))
    {
            
    $urls $m[1];



  •  

    Tags for this Thread

    Posting Permissions

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