【发布时间】:2013-03-20 17:25:01
【问题描述】:
我正在使用JSON API 并希望解析没有 html 标记的帖子内容(明文)。
我尝试使用 htmlspecialchars(json_encode($posts)) 和 strip_tags($posts); 但无法从 JSON 中删除 html 标签。
不确定我是否正确放置它,因为我是 php 新手。
public function get_category_posts() {
global $json_api;
$category = $json_api->introspector->get_current_category();
if (!$category) {
$json_api->error("Not found.");
}
$posts = $json_api->introspector->get_posts(array(
'cat' => $category->id
));
$result = strip_tags($posts);
return $this->posts_object_result($result, $category);
}
JSON:
"posts": [
{
"id": 3454,
"type": "post",
"status": "publish",
"title": "XYZ JOINS",
"content": "<p>This is the content that should not have html tags.<\/p>\n",
"date": "2012-05-16 22:06:55"
}
]
我想从上面的 json 中删除 <p></p> html 标签。内容中有许多 div 和其他 html 标签。
【问题讨论】:
-
您能否提供一些示例输入/输出,说明问题所在以及您希望它的外观,因为目前很难说出您想要什么
-
谢谢!我修改了问题以获得更多说明。
-
strip_tags仅适用于字符串。也许您应该将此功能仅用于Content而不是整个帖子? -
@Philipp 你能举个例子吗?