dqbr37828 2015-06-29 19:36
浏览 11

php标签与正则表达式preg_replace

I have a url let's say : https://stackoverflow.com/example1/ and images tags

<img f="/example2"></img>
<img f="example3"></img>
<img f="http://example4.com"></img>
<img f="https://example5.com"></img>

and here is my regex code for preg_replace:

$regex = "-(src\s*=\s*['\"])(((?!'|\"|http://|https://).)*)(['\"])-i";

so if I use this code in the tags above the output will be :

<img f="https://stackoverflow.com/example1//example2></img>
<img f="https://stackoverflow.com/example1/example3></img>
<img f="http://example4.com/"></img>
<img f="https://example5.com/"></img>

but what I want is /example2 and example3 get replaced too but for /example2 it gets only https://stackoverflow.com/ and for example3 it gets https://stackoverflow.com/example1 ps : I know how to get domain using parse_url. and f= is src ^^

  • 写回答

0条回答 默认 最新

    报告相同问题?