简体   繁体   English

从文件读取的preg_match_all返回空数组

[英]preg_match_all reading from file returns empty array

I'm trying to read a file and filter its content. 我正在尝试读取文件并过滤其内容。 The result I'm expecting is this: https://regex101.com/r/uMTrtd/3 but I don't know why I'm not getting it. 我期望的结果是这样的: https : //regex101.com/r/uMTrtd/3但我不知道为什么我没有得到它。 I've tried changing the PCRE limits with no result and I don't know what else to do. 我尝试更改PCRE限制没有结果,而且我不知道该怎么办。

If I run the preg with the actual string instead of reading the file it works, but the var_dump($file) returns a string. 如果我使用实际字符串运行preg而不是读取文件,则它可以工作,但是var_dump($file)返回一个字符串。

<?php

$file = file_get_contents('myfile.txt');
var_dump($file);
$text = preg_replace('/(cve: .+? Pág\. [0-9]{1,2} )/u','', $file);

$re = '/(La señora|El señor) (.+?):(.+?\. (?=(La señora|El señor) (.+?):|Eran las .+?\.))/u';
preg_match_all($re, $text, $matches, PREG_SET_ORDER, 0);
var_dump($matches);

?>

You can check the content of the file here https://regex101.com/r/uMTrtd/3 您可以在这里查看文件的内容https://regex101.com/r/uMTrtd/3

try this: 尝试这个:

$text = preg_replace('/(cve: .+? Pág\. [0-9]{1,2} )/us','', $file);


$re = '/(La señora|El señor) (.+?):(.+?\. (?=(La señora|El señor) (.+?):|Eran las .+?\.))/us';

"s" makes it search also over newlines “ s”使它也在换行符上搜索

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM