如果我們可以假設…
- HTML標記中<和>字符沒有接受有空格,
- 相同的字符總是通過在條件空格擁抱,並在條件
- 這些組合存在<,>,< =,> =,! <,>
&hellip;這可能是一個解決辦法:
$result = preg_replace('/ ([!]{0,1})(<)([=]{0,1}) /', '$1<$3', $string);
$result = preg_replace('/ ([!]{0,1})(>)([=]{0,1}) /', '$1<$3', $result);
這就是正則表達式表示爲<字符:
\ # Match the character 「 」 literally
( # Match the regular expression below and capture its match into backreference number 1
[!] # Match the character 「!」
{0,1} # Between zero and one times, as many times as possible, giving back as needed (greedy)
)
( # Match the regular expression below and capture its match into backreference number 2
< # Match the character 「<」 literally
)
( # Match the regular expression below and capture its match into backreference number 3
[=] # Match the character 「=」
{0,1} # Between zero and one times, as many times as possible, giving back as needed (greedy)
)
\ # Match the character 「 」 literally
什麼是你當前的字符串?和你想要的字符串是什麼? –
爲什麼不使用正則表達式?我的意思是HTML標記可以包含0個空格,但是當它們不包含時,則必須有其他文本,如href =「/」。 – timmyRS
試試這個: - echo strip_tags($ text); –