例如,我有這個字符串"this is a testing string"
,我想測試天氣詞「串」在那裏。 我將如何在PHP中做到這一點?有沒有辦法在php中檢查字符串中的匹配,比如mysql中的「like」?
$theMessage = addslashes(strip_tags($_POST['message']));
$s1='binuang';
$s2='ilad';
$s3='fraud';
$s4='fake';
$s5='ayaw mo ug tuo';
$s6='pangilad';
$s7='bot2';
$s8='bot-bot';
$s9='botbot';
$s10='di tinuod';
$s11='di ni tinuod';
$t1=strpos($theMessage, $s1);
$t2=strpos($theMessage, $s2);
$t3=strpos($theMessage, $s3);
$t4=strpos($theMessage, $s4);
$t5=strpos($theMessage, $s5);
$t6=strpos($theMessage, $s6);
$t7=strpos($theMessage, $s7);
$t8=strpos($theMessage, $s8);
$t9=strpos($theMessage, $s9);
$t10=strpos($theMessage, $s10);
$t11=strpos($theMessage, $s11);
if($t1===true || $t2===true || $t3===true || $t4===true || $t5===true || $t6===true || $t7===true || $t8===true || $t9===true || $t10===true || $t11===true)
{
$sql2=mysql_query("UPDATE property SET valid='1' where p_id='$q'");
}
嘿。它是這樣的,我使用這個strpos爲我的web應用程序發表評論。所以舉例來說,每當用戶在他的評論中有不好的單詞時,數據庫中的表中的標誌列將具有值1.標誌默認情況下都初始化爲零。所以我所做的是將所有不良詞語存儲到$ s1,$ s2,$ s3 ....等等。並在使用strpos提交評論時比較所有這些。但它不起作用。我的方法錯了嗎? – user628961 2011-03-11 07:30:03
@ user628961,請爲此發佈整個腳本,可能有很多原因導致它無法正常工作。而且,只要你得到你想要的結果,除了一些課程外,沒有對錯的方法。所以,是的,請提交處理這些文字的腳本。這將節省很多時間! – jolt 2011-03-11 09:00:12
我張貼我的代碼上面。提前致謝。 – user628961 2011-03-11 09:22:44