Php strpos删除文本/html

Php strpos删除文本/html,php,xml,parsing,substr,strpos,Php,Xml,Parsing,Substr,Strpos,我正在解析一个XML文件,它的创建者陷入了一堆社交媒体信息中,这对我来说是完全无用的。我想在将数据插入数据库之前删除它 问题是,情况并不完全相同,有些情况是: 做一只社交蝴蝶!连接并了解以下详细信息: 网站•Facebook•Yelp 有些人列出了更多的社交网站,有些人则更少。我真的很想把整个部分都去掉。这也是运行strip_标记后的vardump。原稿是这样的: <strong>Be a Social Butterfly! Connect & Learn More Belo

我正在解析一个XML文件,它的创建者陷入了一堆社交媒体信息中,这对我来说是完全无用的。我想在将数据插入数据库之前删除它

问题是,情况并不完全相同,有些情况是:

做一只社交蝴蝶!连接并了解以下详细信息:
网站•Facebook•Yelp

有些人列出了更多的社交网站,有些人则更少。我真的很想把整个部分都去掉。这也是运行strip_标记后的vardump。原稿是这样的:

<strong>Be a Social Butterfly! Connect & Learn More Below:</br></strong>
<a target="_blank" href="http://www.kiran-indian.com">Website</a> •<a target="_blank" href="http://www.facebook.com/pages/Kiran-Indian-Cuisine/55785994435"> Facebook</a> • <a target="_blank" href="http://www.yelp.com/biz/kiran-indian-cuisine-new-york">Yelp</a>
我的一个朋友建议使用strpos来查找第一个/最后一个部分,并使用substr来删除中间的所有内容,但遗憾的是,我还没有足够的技术来解决这个问题

提前谢谢

描述字段:

Food always does one thing. It helps keep you alive. But it can do more. It can be an experience that educates, transports, and invigorates you. Lunch or dinner at <a target="_blank" href="http://www.kiran-indian.com/home.htmls">Kiran Indian Cuisine</a> a lot more than a chance to keep from starving for another day --- it’s a chance to depart from the norm with delicious homemade dishes using the freshest of ingredients and the most aromatic seasoning available. They are open 7 days a week from 11 a.m. to 11 p.m. and accept all the major credit cards, plus when you order online from the surrounding area, delivery is 100% free of charge.</br></br> <strong>Be a Social Butterfly! Connect & Learn More Below:</br></strong> <a target="_blank" href="http://www.kiran-indian.com">Website</a> •<a target="_blank" href="http://www.facebook.com/pages/Kiran-Indian-Cuisine/55785994435"> Facebook</a> • <a target="_blank" href="http://www.yelp.com/biz/kiran-indian-cuisine-new-york">Yelp</a> 食物总是做一件事。它能让你活下去。但它可以做得更多。它可以是一种教育、运输和激励你的体验。午餐或晚餐的时间远不止是一个避免再挨饿一天的机会——这是一个用最新鲜的原料和最芳香的调味品制作美味家常菜的机会。他们每周7天开放,从上午11点到晚上11点,接受所有主要的信用卡,此外,当您从周边地区在线订购时,送货是100%免费的

做一只社交蝴蝶!连接并了解以下详细信息:
• •
似乎将代码粘贴到此处会自动调整asci/etc。

您需要找到整个文本中第一个字符串的位置,为此使用
strpos
,然后您需要找到要删除的块末尾的位置,再次使用
strpos
。现在您有了要删除的块的起点和终点,请使用
substr\u replace
将其替换为nothing
'
substr\u replace
将要删除的块的长度作为第四个参数,而不是第三个参数的位置,因此需要从第二个位置int减去第一个位置int来计算长度

$feedtext='<description> this part is important...  be a social butterfly .. blah blah etc etc whatever whatever </description>';

$pos1=strpos($feedtext,'be a social butterfly');
$pos2=strpos($feedtext,'</description>');
$len=$pos2-$pos1;
$newtext=substr_replace($feedtext,'',$pos1,$len);

echo $newtext;
$feedtext='这部分很重要。。。做一只社交蝴蝶。。诸如此类等等诸如此类;
$pos1=strpos($feedtext,'be a social butterfly');
$pos2=strpos($feedtext,”);
$len=$pos2-$pos1;
$newtext=substr\u replace($feedtext,,$pos1,$len);
echo$newtext;

测试:

你想删除“.Butterfly..”这句话后面列出的站点,而不考虑站点的数量吗?是的,删除这句话中的所有内容,直到结束。我只是不确定它是如何工作的,因为它从技术上解析了其中的所有信息,然后格式就像:成为一只社交蝴蝶!。。站点列表,ryt?我们能看到feed是什么样子吗?social butterfly部分只是最后一部分。我尝试了上面的代码,我用$feedtext=$value['redemptionLocations']['description'],替换了$feedtext,它输出@mike中的所有内容,您可能需要更改pos1和pos2变量中查找的内容(它们区分大小写)。代码有效,我链接到了一个有效的示例。如果它不起作用,那是因为您试图获取的字符串不在您传递给它的草堆中。这对asci字符有效吗?我试图将pos1设置为“strongBe a Social Buttery”,将pos2设置为“/a”,如果您提供的字符串中正是这样的话($feedtext)然后是,这样就可以了。是否可以在不定义特定字符集的情况下使strpos转到绝对结尾?
$feedtext='<description> this part is important...  be a social butterfly .. blah blah etc etc whatever whatever </description>';

$pos1=strpos($feedtext,'be a social butterfly');
$pos2=strpos($feedtext,'</description>');
$len=$pos2-$pos1;
$newtext=substr_replace($feedtext,'',$pos1,$len);

echo $newtext;