我有一個字符串是這樣的:PHP;如何刪除分隔符和分隔符本身之間的字符串?
My name is <span class="bold">George</span> and I'm <span class="bold">21</span>.
我需要<span class="bold">
和</span>
之間移除一切,這本身定界符。
我需要這樣的輸出:
My name is and I'm .
我試過如下:
$string = "My name is <span class=\"bold\">George</span> and I'm <span class=\"bold\">21</span>.";
$string = preg_replace('/[^<span class="bold">](.*)[^<\/span>]/',' ',$string);
但我沒有得到任何輸出,空白頁。
我在做什麼錯?
用[tag:regex]解析[tag:html]是[ill suggest](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags )。 – Xorifelse
@Xorifelse問題是我正在使用'mb_strimwidth($ string,0,300,'...','utf-8')'。如果這在html標籤結束我的佈局「崩潰」。否則,我會,當然,使用CSS。 – David
這是你認爲會導致問題的原因嗎?否。問題是[每次嘗試用正則表達式解析HTML時,邪惡的孩子哭處女的血,和俄羅斯的黑客PWN你的web應用(http://stackoverflow.com/a/1732454/4982088)。 – Xorifelse