-1

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"
}
]

<p></p>上記のjsonからhtmlタグを削除したい。コンテンツには多くの div およびその他の html タグがあります。

4

1 に答える 1

0

必要なのは、コンテンツから html スタイルのタグを取り除く単純な正規表現だけだと思います。多分これはうまくいくでしょう

str.replace(/<\/?[^>]+>/gi, '')
于 2013-03-20T17:44:32.280 に答える