Preg_match PHP help needed - $5?

kimkils

Power Member
Joined
Jan 10, 2009
Messages
669
Reaction score
231
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
 

bartemt

Registered Member
Joined
Jun 23, 2010
Messages
81
Reaction score
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.
 
Top