dongqiu5184 2014-10-19 10:31
浏览 40
已采纳

从mysql查询结果的php数组

what i try to do ? i try to make code to found if there duplicate data into database or not ,that data it text Content written by users . so i make sql query to get result of row pagetext from database and clean it from any Signs And coordinate (font color, font size, and font type) and image links or any links , and same i do it for Variable $post['message'] that get Content of text area .. than i check if Content of $post['message'] is same Content of pagetext or not !

Full code :

// 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;
    }
        }
            }

My problem ? my code Almost correct , but my problem in those lines [square brackets] . when i try great array for my result

// 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);

if i used only first line without used preg_replace the code works good . when i use [square brackets] for a

$pagetext[] = stripBBCode($ckeckpagetext['pagetext']);
  • 写回答

2条回答 默认 最新

  • duanran8648 2014-10-19 14:06
    关注
        $pagetext = array();
        while ($ckeckpagetext = $db->fetch_array($ckeck))    
        {
            $tmpCheckPageText = stripBBCode($ckeckpagetext['pagetext']);
            $tmpCheckPageText = preg_replace('/[\s]+/mu','', $tmpCheckPageText);
            $tmpCheckPageText = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $tmpCheckPageText); 
            $pagetext[] = $tmpCheckPageText;
        }
    

    And array is:

    $pagetext = array( 'Plain text1', 'Plain text2' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?