1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

preg_match_all small help

Discussion in 'PHP' started by DjZoC, Jun 30, 2012.

  1. #1
    Hello there, i have one small problem and dont know how to fix it, hope someone can help me with this

    
       $Source      = $cURL->cURL_Data( $cURL_Array );
       
       $preg_code_1 = "/<a href=\"(.*?)\"(.*?)>(.*?)<\/a>/is";
    
       preg_match_all($preg_code_1, $Source, $links_source);
       
       $Links_Array = array();
       
       foreach($links_source as $link) {
        $Links_Array = array(
         $link[1]        => $link[3],
        );
    	 echo $link[1];
       }
       
       foreach($Links_Array as $URL => $Title) {
        echo "Url - " . $URL . "<br />Title - " . $Title . "<br /><br />\n\n";
       }
    PHP:
    is not show me all the urls from the source ...
     
    DjZoC, Jun 30, 2012 IP
  2. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #2
    Using regular expressions to extract links from a web page is not the way to go.

    Use DOMDocument().. It should be included with your PHP distribution. Example:

    
    <?php
    $html = $cURL->cURL_Data( $cURL_Array );
    
    $dom = new DOMDocument;
     
    @$dom->loadHTML($html);
     
    $links = $dom->getElementsByTagName('a');
     
    foreach ($links as $link)
    {
        print $link->getAttribute('href') . "<br>\n";
    }
    ?>
    
    PHP:
     
    Last edited: Jun 30, 2012
    NetStar, Jun 30, 2012 IP
  3. DjZoC

    DjZoC Member

    Messages:
    167
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    cool man thanks :D
     
    DjZoC, Jun 30, 2012 IP
  4. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #4
    I accidentally put a ' before the semi-colon. I fixed it. It works.
     
    NetStar, Jun 30, 2012 IP