我做了一些工作,我从Google API搜索结果片段中获取了一个字符串。在此字符串中包含<b>
和</b>
这会产生进一步工作的问题,因此我需要删除<b>
和</b>
主要字符串代码:
$content_all .="#$*@#" . $json->responseData->results[$x]->content;
我尝试使用此代码后删除<b>
和</b>
:
$content_all=(string)$content_all;
str_replace("<b>", " ", $content_all);
str_replace("</b>", " ", $content_all);
但不会删除<b>
和</b>
。
我试过了
str_replace("hello", " ", "Hello people");
这很有用。但是为什么它不适用于$content_all
刺痛。
我写了$ content_all的值,它看起来像这样
#$*@#These <b>sad songs</b> will definitely make you shed tears...unless you're a robot.#$*@#Check out our top 35 <b>songs</b> about heartbreak. Did we miss any? Let us know!#$*@#Feb 10, 2014 <b>...</b> "Somewhere Somehow" available on iTunes now! http://smarturl.it/somewhere-
somehow Music video by We The Kings performing <b>Sad Song</b> ...#$*@#Nov 12, 2015 <b>...</b> There's nothing like a <b>sad</b>, slow <b>song</b> to aid in a postbreakup cry or to be the
soundtrack to a bad day. It's a well-known fact that music is made ...#$*@#May 12, 2015 <b>...</b> Yes, <b>sad songs</b> do say so much. And these 50 songs helped the Paste staff to
hurt so good. I tried to keep it to one song per artist but Johnny ...#$*@#Just Cry, <b>Sad Songs</b>. Indiemono. The saddest and original playlist on Spotify, '
Just Cry, <b>Sad Songs</b>', it's been active for 3 years, time of ... Song, Artist, Album ...#$*@#<b>sad songs</b>, <b>sad song</b>, saddest song in the world, world´s saddest song, battle
song, sadsong, love song.#$*@#Last month we made a playlist of the 50 most uplifting songs ever. Now, we look
at the opposite: 50 beautifully <b>sad songs</b>, beginning with Amy Winehouse ...#$*@#Are you looking for the best <b>sad songs</b>? Look no further, this post contains our
favorite 20 <b>sad songs</b> of all time (as of 2015)!#$*@#8tracks radio. Online, everywhere. - stream 2500+ <b>sad songs</b> playlists including
sad, Coldplay, and indie music from your desktop or mobile device.#$*@#Nov 6, 2015 <b>...</b> We will also be engaging in the ritual of indulging our completely unnecessary,
sun-affected sadness by playing sad, <b>sad songs</b> on infinite ...#$*@#"<b>Sad Songs</b> (Say So Much)" is a song by Elton John and is the closing track on
the 1984 album Breaking Hearts. It reached the No 5 on the U.S. chart. The lyrics
...#$*@#<b>Sad Songs</b> for Dirty Lovers is the second studio album by indie rock band The
National. It was released in 2003 on Brassland Records. This is the first album on
...#$*@#Sep 24, 2015 <b>...</b> The popular belief that a <b>song</b> can be so <b>sad</b> that it can trigger suicide has a long
history. Written in 1933 by Hungarian composer Seress and ...#$*@#The National - <b>Sad Songs</b> for Dirty Lovers - Amazon.com Music.#$*@#<b>Sad Songs</b> 1 Songs download Free Music Latest New Top Best Hit Play Trend
Albums Single djjohal com 20 online dj remix.
答案 0 :(得分:6)
如果要从字符串中删除html标记,可以使用strip_tags()
例如:
<?php
echo strip_tags("Hello <b>world!</b>");//Hello world
?>
小心strip_tag将删除字符串中的所有标记。
参考http://www.w3schools.com/php/func_string_strip_tags.asp。
如果您使用str_replace("<b>", " ", $content_all);
,还会产生不必要的空间
ie:str_replace("<b>", " ", "hi <br><br> vig");
result: hi vig
答案 1 :(得分:5)
你必须这样做:
$content_all=str_replace("<b>", " ", $content_all);
$content_all=str_replace("</b>", " ", $content_all);
echo $content_all;
当然,最后一行只是一个回声,所以你可以看到结果。