簡體   English   中英

與Json一起使用Preg_replace

[英]Using Preg_replace with Json

所以我試圖用#texthere來獲取任何內容,然后將其更改為鏈接,以便我可以將其導航到該特定哈希的哈希頁面。

有了代碼,我一直保持“未定義”的狀態。 有人可以看看一下,指出我要去哪里了。

$json = array(
'userpost' => array()
);

$row = mysqli_fetch_assoc($check1);

        $posts = array();

         $posts['num'] = $num;
         $posts['streamitem_id'] = $row['streamitem_id'];
         $autoembed = new AutoEmbed();
         $posts['streamitem_content'] = $autoembed->parse($row['streamitem_content']);
         $regex = "/#(\w+)/"; 
         $string=$row['streamitem_content'];
         $string = preg_replace($regex, '<a href="hash.php?tag=$1">$1</a>', $string); 
         $posts['streamitem_content']=json_decode($string);
         $posts['streamitem_creator'] = $row['streamitem_creator'];
         $posts['streamitem_timestamp'] = $row['streamitem_timestamp'];
         $posts['username'] = $row['username'];
         $posts['id'] = $row['id'];
         $posts['first'] = $row['first'];
         $posts['middle'] = $row['middle'];
         $posts['last'] = $row['last'];

$json['userpost'][] =  $posts;

echo json_encode($json);

好的,這就是我要解決的問題。 無需解碼,這就是造成此問題的原因。

   $regex = "/#(\w+)/"; 
    $posts['streamitem_content'] = $row['streamitem_content'];
    $posts['streamitem_content'] = preg_replace($regex, "
    <a href='hash.php?tag=$1'>$1</a>",  $posts['streamitem_content'] ); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM