1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Preg_match PHP help needed - $5?

Discussion in 'PHP & Perl' started by kimkils, Sep 4, 2010.

  1. kimkils

    kimkils Power Member

    Joined:
    Jan 10, 2009
    Messages:
    663
    Likes Received:
    225
    This is what i want to read out from a html file , 600, 800);return false;">some text that changes</a>

    I want the text between the > and the <

    (There are about 400 of these... i want every two occurrences of it, or all of them and i will sort it afterwards)

    This is what ive come up with - it doesnt work obviously

    Code:
    $website = "1.html";
    		
    		$curl = curl_init();
    		curl_setopt($curl, CURLOPT_URL, $website);
    		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    		 
    		$page = curl_exec($curl);
    		curl_close($curl);      //;return false;">100.00% USD</a>
    					
    		preg_match("/(;return false;\">)(.*?)(</a>)/", $page, $match);
    		
    		echo "First result".$match[1];
    		echo count($match);
    Please can someone help me out and describe exactly what the command does, ive read a tutorial but its late and my head hurts :confused::confused:

    $5, a +rep, a digital kiss, whatever you want, just please help :p
     
  2. kimkils

    kimkils Power Member

    Joined:
    Jan 10, 2009
    Messages:
    663
    Likes Received:
    225
    bumpity bump... :ciao:
     
  3. paincake

    paincake Power Member

    Joined:
    Aug 18, 2010
    Messages:
    716
    Likes Received:
    3,099
    Home Page:
    I sent you a PM.
     
    • Thanks Thanks x 1
  4. bartemt

    bartemt Registered Member

    Joined:
    Jun 23, 2010
    Messages:
    81
    Likes Received:
    25
    Code:
    <?php
    
    preg_match_all('/;return false;">([^<]*)/', $page, $matches);
    
    for($i = 0;$i<count($matches[1]);$i++)
    {
    echo $matches[1][$i];
    echo '<br>';
    }
    
    
    
    ?>
    preg_match_all and only regular expressing the parts that you want in brackets for the win. The match will be an array of arrays, with [0] being fullmatches and [1] being the bracket matches, what we want.