我正在解析一個XML文件,它的創建者卡在一羣完全沒用的社交媒體信息中。我想在將數據插入數據庫之前刪除它。strpos刪除文本/ html
問題是,它不是都一樣,有些事件是:
Be a Social Butterfly! Connect & Learn More Below: Website • Facebook • Yelp
一些有更多的社交網站上市,有些還少。我真的很想刪除整個部分。在運行strip_tags之後,這也是一個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>
我使用的preg_replace擺脫日整個句子的「社交人脈......」與
$description = strip_tags(preg_replace('/\bBe a Social Butterfly! Connect & Learn More Below\b/', '', $value['redemptionLocations']['description']));
我的一個朋友建議使用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>
似乎粘貼代碼到這裏自動調整ASCI /等。
要刪除的那句話後列出的網站「..Butterfly ..」,無論網站的數量? – Samih3
是的,從該句子中刪除所有內容,直到 description>結束。我只是不知道這是如何工作的,因爲它技術上解析 –
Mike
裏面的所有信息然後格式是這樣的:是一個社會蝴蝶!..網站列表 description>,ryt? –
Samih3