我正在尝试建立一个脚本,搜索网页上的一个特定的单词。每当我运行脚本时,它都会返回单词存在,即使它不存在。
脚本是这样的:
<?php
$db->query("select id from ".prefix." book where book='$book'");
$id=$db->f("id");
$text = file_get_contents('http://www.somesite.com/item?keywords=$id');
echo (stristr ($text, 'Eminescu')) ? 'Online' : 'Offline';
?>发布于 2013-09-20 07:36:03
在不知道为什么要使用stristr的情况下,我会说直接使用strpos (http://ca2.php.net/manual/en/function.strpos.php)。
$text = file_get_contents('http://www.somesite.com/item?keywords=$id');
$intext = strpos($text, 'Eminescu') !== false; // note !==, not !=
echo $intext ? 'Online' : 'Offline';但是这是相当愚蠢的,因为你只是在搜索子字符串。如果html包含"LollerphanEminescutiomatic",则此代码(以及您试图编写的代码)将显示“是的,它在那里”。这将是正确的,但结果可能是无用的。
https://stackoverflow.com/questions/18902545
复制相似问题