我正在使用JSON API,並且希望在沒有html標記的情況下解析發佈內容(明文)。如何獲得沒有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標籤。
你能給什麼是錯的一些樣品輸入/輸出以及你如何喜歡它的樣子,因爲它是一個有點困難,告訴你想要什麼,此刻 – 2013-03-20 17:30:13
謝謝!我修改了這個問題以獲得更多的解釋。 – updev 2013-03-20 17:38:23
'strip_tags'只能用於字符串..也許你應該使用這個函數僅僅用於'Content'而不是整個Posts? – Philipp 2013-03-20 17:46:28