我的帖子是使用wysiwyg编辑器中的html标签保存的。
我想要删除所有html标签的json输出。
因为strip_tags有时可以删除文本,所以我正在使用preg_replace:
$body = $row['content'];
//$body = strip_tags($body);
$body = preg_replace("/<img[^>]+\>/i", "", $body);
$regex_strip_tags = "/<[\/\!]*?[^<>]*?>/";
$body = preg_replace($regex_strip_tags, '' , $body);
将其存放在数组中:
$arr[] = array('body' => $body);
问题是当我echo json_encode($arr)
时,某些条目会显示null
,但如果我使用print_r($arr)
,我会看到所有内容。
不确定这里发生了什么。