2016-09-13 7 views
0

私はかなり新しいPHPです。 jsとしか仕事していません。しかし、私は現在、facebook/twitterで共有されるpost blurbを作成しようとしています。とにかくtumblr apiが抜粋を返すので、何よりも練習のほうが多くなります。 私はtumblrを私の "バックエンド"として使用しています。tumblrに投稿するものは、ウェブサイトに表示されます。かくかくしかじか。 私はphpを使ってtumblrのデータをjsonとして取得し、json_decodeを使って変数に格納します。PHP、Tumblr APIからHtml書式を取り除く効率的な方法return

ここで、すべてのhtmlを削除して標準の文字列として処理しようとする私の現在のコードは、私が知りたいことは... phpで同じ結果を達成するより効率的な方法ですURLはFacebook/Twitterで呼び出されます...私の終わりは投稿の説明を表示できます。

$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" 

再び。最終結果を達成するためのより効率的な方法はありますか?

答えて

2

PHPのstrip_tags機能を試しましたか?以下

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

例は、上記のリンクからです:

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

の出力は以下となります。

Test paragraph. Other text 
+0

うん、あなただけのすべてのタグを削除したい場合は、これは、かなりうまく動作するはずです – Bolovsky

+0

乾杯、私はそれを試してみましょう! –

関連する問題