【发布时间】:2021-05-28 10:13:13
【问题描述】:
我正在尝试使用此代码执行 php 搜索:
$search = &q;
$lines = file('file.txt');
// Store true when the text is found
$found = false;
foreach($lines as $line)
{
if(strpos($line, $search) !== false)
{
$found = true;
echo $line;
}
}
// If the text was not found, show a message
if(!$found)
{
echo '';
它搜索每个字符并且有时返回而没有结果。我想将此代码设置为仅搜索字母和数字,但不包含任何特殊字符,包括点和逗号。我该怎么做? 谢谢。
【问题讨论】:
-
$search = &q;应该会抛出错误。您可以使用正则表达式来执行此操作。你有没有尝试过? -
你没有给出任何
$line的例子或者你想从中得到什么,那么别人怎么知道你想要什么?
标签: php search special-characters