Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php preg_match_all不';t回复匹配数组?_Php_Regex_Preg Match - Fatal编程技术网

Php preg_match_all不';t回复匹配数组?

Php preg_match_all不';t回复匹配数组?,php,regex,preg-match,Php,Regex,Preg Match,我对preg_match_all有问题。 preg_match会将整个匹配作为数组的第一个元素进行回复,而preg_match_all不会—第一个数组为空。 至少我选择的模式(因为它是我需要的,所以没有尝试过其他模式)不起作用。 这是我的密码: preg_match_all("/<\?\?(\t| )?translate(\t| )?;(\t| )?(.*)(\t| )?\?\?>/U", $file, $translate_info); preg\U match\U all(//

我对preg_match_all有问题。 preg_match会将整个匹配作为数组的第一个元素进行回复,而preg_match_all不会—第一个数组为空。 至少我选择的模式(因为它是我需要的,所以没有尝试过其他模式)不起作用。 这是我的密码:

preg_match_all("/<\?\?(\t| )?translate(\t| )?;(\t| )?(.*)(\t| )?\?\?>/U", $file, $translate_info);
preg\U match\U all(//U“,$file,$translate\U info);

模式本身正在工作并生成子模式匹配。

根据新的给定详细信息进行更新:

$file = '<?? translate ; foo bar??>';
$res = preg_match_all('/<\?\?(\t| )?translate(\t| )?;(\t| )?(.*)(\t| )?\?\?>/U', $file, $translate_info);
echo "res='$res'\n";
var_dump($translate_info);
$file='';
$res=preg_match_all('//U',$file,$translate_info);
echo“res='$res'\n”;
变量转储($translate\u info);
对我有效,它提供:

res='1'
array(6) {
  [0]=>
  array(1) {
    [0]=>
    string(26) "<?? translate ; foo bar??>"
  }
  [1]=>
  array(1) {
    [0]=>
    string(1) " "
  }
  [2]=>
  array(1) {
    [0]=>
    string(1) " "
  }
  [3]=>
  array(1) {
    [0]=>
    string(0) ""
  }
  [4]=>
  array(1) {
    [0]=>
    string(8) " foo bar"
  }
  [5]=>
  array(1) {
    [0]=>
    string(0) ""
  }
}
res='1'
阵列(6){
[0]=>
阵列(1){
[0]=>
字符串(26)”
}
[1]=>
阵列(1){
[0]=>
字符串(1)”
}
[2]=>
阵列(1){
[0]=>
字符串(1)”
}
[3]=>
阵列(1){
[0]=>
字符串(0)”
}
[4]=>
阵列(1){
[0]=>
字符串(8)“foo-bar”
}
[5]=>
阵列(1){
[0]=>
字符串(0)”
}
}

您能发布您试图匹配的数据吗?如果我这样做,它就找不到任何东西了。如果我逃过他们一次,也一样。我在寻找,天哪,我很笨,