Reputation:
For one reason or another this (messy thing) doesn't work.. it's messy because I changed so much to find out what is wrong..
Problem: preg_match("/\"h4(.*?)/h4/s", $theMAGICresult, $output_game);
I know the match works.. (normaly); I did check on http://www.phpliveregex.com/. I did it in a foreach loop, while loop.. I try preg_match_all.. I supply a correct pattern, a correct string for subject and I put it in a correct array and fetch it but it is empty.. after 2 hours of finding an answer I give up.. can you help me ??
preg_match_all("/<li class=\"completed\">(.*?)<\/li>/s", $all, $output);
/* $all contains something like xx <li class="completed"> xxxx"h4GOLDFISH/h4xxxxxx</li>xxxxxxxxxxxx */
$arrayLoop = array(); //makes sure it's an array
$arrayLoop = $output[0]; // makes $output[0] the default array
//$arrayLoop[0] is now <li class="completed"> xxxx"h4GOLDFISH/h4xxxxxx</li>
$i = 1; //while loop because, had first foreach loop etc..
while($i < count($arrayLoop)) {
$theMAGICresult = $arrayLoop[$i]; // to be sure $arrayLoop[$i] is valid
//theMAGICresult is now : <li class="completed">xx"h4GOLDFISH/h4xxxxxx</li>
preg_match("/\"h4(.*?)\/h4/s", $theMAGICresult, $output_game);
echo $output_game[1]; //is nothing while is should have GOLDFISH
$i++;
}
print_r($output_game); //empty array
Upvotes: 0
Views: 112
Reputation: 618
try with:
preg_match("/\\"h4(.*?)\/h4/s", $input_line, $output_array);
Fixed example:
$output_game = [];
$theMAGICresult = '<li class="completed">xx"h4GOLDFISH/h4xxxxxx</li>';
preg_match('/\"h4(.*?)\/h4/s', $theMAGICresult, $output_game);
var_dump($output_game);
Upvotes: 1