preg_replace 突然停止区分
困惑了。我一直在使用下面的 IF PREG_MATCH 来区分整个单词和其他单词的一部分。它突然停止在该脚本以及我使用的依赖于该命令的任何其他脚本中运行。
结果是它找到了部分单词,尽管您可以看到它被明确告知只能查找整个单词。
$word = preg_replace("/[^a-zA-Z 0-9]+/", " ", $word);
if (preg_match('#\b'.$word.'\b#',$goodfile) && (trim($word) != "")) {
$fate = strpos($goodfile,$word);
print $word ." ";
print $fate ."</br>";
Confounded. I've been using the below IF PREG_MATCH to distinguish between words which entire words and words which are parts of other words. It has suddenly ceased to function in this script, and any other script I use, which depend on this command.
The result is it finds parts of words, although you can see it is explicitly told to find only entire words.
$word = preg_replace("/[^a-zA-Z 0-9]+/", " ", $word);
if (preg_match('#\b'.$word.'\b#',$goodfile) && (trim($word) != "")) {
$fate = strpos($goodfile,$word);
print $word ." ";
print $fate ."</br>";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想读取文本文件一行的第一个单词,就像您的标题所示,请尝试另一种方法:
If you only want to read the first word of a line of a text file, like your title suggests, try another method:
这比爆炸更快更干净,而且你不会制作任何数组
This would be faster and cleaner than explode and you won't be making any array