I somehow can't get this to work: I have a simple string, for example:(preg_replace函數)正則表達式替換<a href="">
<p>Foo & Bar</p> // <-- this should still be &
<a href="http://test.com/?php=true&test=test&p=p"> // <- This string should only be affected and be changed to &
<div> Yes ü No</div> // <-- This should still be ü
<a href="http://mycoolpage.com/?page=1&fun=true&foo=bar&yes=no">
Now I want to replace all the &
with only &
with preg_replace
and I tried to create a regex for this, but somehow I can't get it to work.
This is how far I've come, it finds only the last &
and also matches the whole string before it and fails to find the other. What am I doing wrong?
(?>=href\=\").*?(&)(?=\")
Edit: It is not possible to use htmlentities_decode or htmlspecialchars_decode, as there is other Code that would get affected.
試過'html_entity_decode'所有與放大器? https://ideone.com/6DyYuQ –
或者更難的方法:https://ideone.com/ADku3b –
我會嘗試'while(正則表達式匹配){str替換}' –