当前位置:  开发笔记 > 编程语言 > 正文

在PHP中从字符串中删除字符串的一部分

如何解决《在PHP中从字符串中删除字符串的一部分》经验,为你挑选了2个好方法。

我做了一些工作,我从Google API搜索结果片段中获取了一个字符串.在这个字符串中包含,这为进一步的工作带来了问题,所以我需要删除

主要字符串代码:

$content_all .="#$*@#" . $json->responseData->results[$x]->content;

我尝试此代码后删除:

 $content_all=(string)$content_all;
str_replace("", " ", $content_all);
str_replace("", " ", $content_all);

但它不会删除.我试过了

str_replace("hello", " ", "Hello people");

它奏效了.但为什么它不适合$content_all刺痛.我写了$ content_all的值,它看起来像这样

#$*@#These sad songs will definitely make you shed tears...unless you're a robot.#$*@#Check out our top 35 songs about heartbreak. Did we miss any? Let us know!#$*@#Feb 10, 2014 ... "Somewhere Somehow" available on iTunes now! http://smarturl.it/somewhere-
somehow Music video by We The Kings performing Sad Song ...#$*@#Nov 12, 2015 ... There's nothing like a sad, slow song 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 ... Yes, sad songs 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, Sad Songs. Indiemono. The saddest and original playlist on Spotify, '
Just Cry, Sad Songs', it's been active for 3 years, time of ... Song, Artist, Album ...#$*@#sad songs, sad song, 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 sad songs, beginning with Amy Winehouse ...#$*@#Are you looking for the best sad songs? Look no further, this post contains our 
favorite 20 sad songs of all time (as of 2015)!#$*@#8tracks radio. Online, everywhere. - stream 2500+ sad songs playlists including 
sad, Coldplay, and indie music from your desktop or mobile device.#$*@#Nov 6, 2015 ... We will also be engaging in the ritual of indulging our completely unnecessary, 
sun-affected sadness by playing sad, sad songs on infinite ...#$*@#"Sad Songs (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
 ...#$*@#Sad Songs 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 ... The popular belief that a song can be so sad that it can trigger suicide has a long 
history. Written in 1933 by Hungarian composer Seress and ...#$*@#The National - Sad Songs for Dirty Lovers - Amazon.com Music.#$*@#Sad Songs 1 Songs download Free Music Latest New Top Best Hit Play Trend 
Albums Single djjohal com 20 online dj remix.

Vigneswaran .. 6

如果你想从字符串中删除html标签你可以去strip_tags()

例如:

   world!");//Hello world
   ?>

小心strip_tag将删除字符串中的所有标记.

请参阅http://www.w3schools.com/php/func_string_strip_tags.asp.

如果你使用str_replace("", " ", $content_all);它还有一件事它会给你不想要的空间

ie:str_replace("", " ", "hi 

vig"); result: hi vig


Marcovecchio.. 5

你必须这样做:

$content_all=str_replace("", " ", $content_all);
$content_all=str_replace("", " ", $content_all);

echo $content_all;

当然,最后一行只是一个回声,所以你可以看到结果.



1> Vigneswaran ..:

如果你想从字符串中删除html标签你可以去strip_tags()

例如:

   world!");//Hello world
   ?>

小心strip_tag将删除字符串中的所有标记.

请参阅http://www.w3schools.com/php/func_string_strip_tags.asp.

如果你使用str_replace("", " ", $content_all);它还有一件事它会给你不想要的空间

ie:str_replace("", " ", "hi 

vig"); result: hi vig



2> Marcovecchio..:

你必须这样做:

$content_all=str_replace("", " ", $content_all);
$content_all=str_replace("", " ", $content_all);

echo $content_all;

当然,最后一行只是一个回声,所以你可以看到结果.

推荐阅读
虎仔球妈_459
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有