我有一個查詢,當我用「回聲」測試,效果很好:這個REGEXP迴應了一件事,但又進入了MySQL。爲什麼?
$url = "http://search.twitter.com/search.json?q=&ands=&phrase=&ors=¬s=RT%2C+%40&tag=andyasks&lang=all&from=amcafee&to=&ref=&near=&within=15&units=mi&since=&until=&rpp=50";
$contents = file_get_contents($url);
$decode = json_decode($contents, true);
foreach($decode['results'] as $current) {
if(preg_match("/\?/", "$current[text]")){
echo $current[text]."<br />";
}
}
但是,當我將其更改爲它創建一個數據庫,它失去了一個記錄:
$url = "http://search.twitter.com/search.json?q=&ands=&phrase=&ors=¬s=RT%2C+%40&tag=andyasks&lang=all&from=amcafee&to=&ref=&near=&within=15&units=mi&since=&until=&rpp=50";
$contents = file_get_contents($url);
$decode = json_decode($contents, true);
foreach($decode['results'] as $current) {
$query = "INSERT IGNORE INTO andyasks (questions, date, user) VALUES ('$current[text]','$current[created_at]','Andy')";
if(preg_match("/\?/", "$current[text]")){
mysql_query($query);
}
}
具體來說,它跳過的Tweet是「amcafee:#andyasks本月晚些時候在波士頓的Enterprise 2.0會議參與者應該怎麼做?#e2conf」。這是第一個回聲,但是在DB INSERT中被忽略了。有什麼想法嗎?
strpos()會更簡單和更快速在這種情況下,例如if(strpos($ current ['text'],'?')!== false) – 2009-06-12 21:13:25
今天要學習的另外一個PHP函數我想,謝謝你的提示;我很重要我沒有使用過90%的功能,所以我什至不知道在參考文獻中查找。謝謝。 – 2009-06-12 21:21:04