PHP,从 Tumblr API 删除 Html 格式的有效方法 return

PHP, Efficient Way to Remove Html Formatting From a Tumblr API return

所以我是 php 的新手。只用过js。但我目前正在尝试自己创建要在 facebook/twitter 上共享的 post 简介。无论如何,更多的是练习,然后是 tumblr api returns 的摘录。 简而言之,我正在使用 tumblr 作为我的 "backend",我在 tumblr post 上的内容将出现在网站上。布拉布拉布拉。 我有 php 将 tumblr 数据检索为 json 并使用 json_decode.

放入变量中

这是我当前的代码,用于删除所有 html 并尝试将其作为标准字符串处理,我想知道的是...是否有更有效的方法来实现相同的结果php,所以当 facebook/twitter 调用 url 时...我的终端将能够提供 post.

的描述
    $json_TumblrDecoded = json_decode($tmblrjson, true);
    $reducedBodyText = str_replace(array('  '), ' ', str_replace(array('.'), '. ' , str_replace(array("\r", "\n"), ' ', strip_tags(html_entity_decode(substr($json_TumblrDecoded['response']['posts']['0']['body'],0,400)))))); 

哪个会转这个;

<p>Keeping this post short.<br/>Good Movie, not Great Movie.<br/>It felt like there was a lot cut out (Apparently 40mins worth was).<br/>I think this is a really positive direction for movies based on video games to be headed.<br/>I can’t wait for a directors cut. <br/><br/>7/10 - Go and see it! <br/>It may not be the movie we deserved, but perhaps this is the movie we needed, if not just to get the franchise off the ground. I really think a sequel will prove what is capable.</p>

进入这个;

"Keeping this post short. Good Movie, not Great Movie. It felt like there was a lot cut out (Apparently 40mins worth was). I think this is a really positive direction for movies based on video games to be headed. I can’t wait for a directors cut.  7/10 - Go and see it! It may not be the movie we deserved, but perhaps this is the movie we needed, if not just to ge"

再次。是否有更有效的方法来实现最终结果?

你试过PHP的strip_tags功能了吗?

http://php.net/manual/en/function.strip-tags.php

下面的示例来自上面的 link:

<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);

将输出:

Test paragraph. Other text