[英]Using Preg_replace with Json
So I have attempted to get anything with a #texthere t change to a link so i can navigate them to the hash page of that specific hash. 所以我试图用#texthere来获取任何内容,然后将其更改为链接,以便我可以将其导航到该特定哈希的哈希页面。
With the code I have I just keep getting 'undefined' back. 有了代码,我一直保持“未定义”的状态。 Can someone please take a look and point out where I am going wrong.
有人可以看看一下,指出我要去哪里了。
$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);
Okay this is what I've done to fix the issue. 好的,这就是我要解决的问题。 no decoding needed and that is what was causing the issue.
无需解码,这就是造成此问题的原因。
$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.