我試圖做什麼? 我嘗試做代碼來發現是否有重複的數據到數據庫中,數據是否是文本內容由用戶編寫。 所以我讓sql查詢從數據庫中獲得行pagetext
的結果,並從任何符號和座標(字體顏色,字體大小和字體類型)和圖像鏈接或任何鏈接清理它,並且我也爲變量$post['message']
文本區域的內容.. 比我檢查是否$post['message']
的內容相同pagetext
的內容與否!從mysql查詢結果php數組
全碼:
// FUNCTION TO CLEAN TEXT
function stripBBCode($text_to_search)
{
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
return preg_replace($pattern, $replace, $text_to_search);
}
// MYSQL QUERY
$ckeck = $db->query_read(" SELECT pagetext FROM " . TABLE_PREFIX . " post ");
$ckeck_num = mysql_num_rows($ckeck);
while ($ckeckpagetext = $db->fetch_array($ckeck))
{
// RESULT FROM QUERY - here i try to make ARRAY BY [square brackets]
$pagetext[] = stripBBCode($ckeckpagetext['pagetext']);
$pagetext[] = preg_replace('/[\s]+/mu','', $pagetext);
$pagetext[] = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $pagetext);
// Variable
$message = stripBBCode($post['message']);
$message = preg_replace('/[\s]+/mu','',$message);
$message = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $message);
// LOOP
for($x=0; $x<$ckeck_num; $x++)
{
// CHECK IF THERE duplicate TEXT OR NOT
if ($message == $pagetext[$x])
{
$ckeck_duplicate = 1;
}else{
$ckeck_duplicate = 2;
}
}
}
我的問題? 我的代碼幾乎正確,但我的問題在這些行[方括號]。當我爲我的結果
// RESULT FROM QUERY
$pagetext[] = stripBBCode($ckeckpagetext['pagetext']);
$pagetext[] = preg_replace('/[\s]+/mu','', $pagetext);
$pagetext[] = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $pagetext);
,如果我只用第一線,而不使用preg_replace
嘗試大陣代碼工作良好。 當我使用[方括號]爲
$pagetext[] = stripBBCode($ckeckpagetext['pagetext']);
你可能想看看這個問題。 http://stackoverflow.com/questions/26449506/php-extracting-string-between-two-tags-by-childs-content – addicted20015 2014-10-19 10:33:17
@ addicted20015我會看看它現在thnx – 2014-10-19 10:45:38
@ addicted20015,這不是我想..事實上,遠離我想要做的事 – 2014-10-19 10:47:35