Preg_Match无法正常工作

时间:2015-07-20 16:46:57

标签: php preg-match

出于某种原因,这个(凌乱的东西)不起作用..它很乱,因为我改变了很多,以找出问题所在。

  

问题:preg_match(“/ \”h4(。*?)/ h4 / s“,$ theMAGICresult,$ output_game);

     

我知道这场比赛有效..(正常);我确实检查过   http://www.phpliveregex.com/。我在foreach循环中完成它,而循环..   我尝试preg_match_all ..我提供了一个正确的模式,一个正确的字符串   对于主题,我把它放在一个正确的数组并获取它,但它是   空了...经过2个小时的寻找答案我放弃了..你能帮助我吗?   ??

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

1 个答案:

答案 0 :(得分:2)

尝试:

preg_match("/\\"h4(.*?)\/h4/s", $input_line, $output_array);

修复示例:

$output_game = [];
$theMAGICresult = '<li class="completed">xx"h4GOLDFISH/h4xxxxxx</li>';
preg_match('/\"h4(.*?)\/h4/s', $theMAGICresult, $output_game);
var_dump($output_game);