0
我在我的PHP代碼中有一個變量,其中它等於存儲的字符串。 該字符串的一小部分被用作另一頁上的預覽。 有時會出現的Javascript在該字符串,我怎麼可能說以下內容:從字符串中刪除子字符串,其中只有字符串的開頭和結尾已知
Pseudocode:
if stringVar contains "<script"
then remove the substring starting at "<script" and ending at "/script>"
你確定該文本中,你會發現_永遠_「<腳本」,或者另一個實例「/ SCRIPT>」在實際結束之前?如果你是這樣的話,聽起來這對於用正則表達式替換來說是微不足道的。附:這聽起來像想[解析HTML](http://stackoverflow.com/q/1732348/540162) - 如果是這樣的話,不要這樣做;改爲使用XML解析器。 – Nightfirecat
你是否偶然尋找['strip_tags'](http://php.net/strip_tags)? – deceze