-7

There is a code:

$s = <<<HD
...
<img title="blablabla" alt='blabla' src='//domain.net/images/image.jpg'>
...
<img alt="bla " src="//domain.com/imgs/1.png" title='blabla' />
...
<img src="/images/img.gif">
...
HD;
$s = preg_replace(' **???** ', $s);

At The output should be:

<img alt='blabla' src='image.jpg'>
<img alt='bla' src='1.png'>
<img alt='' src='img.gif'>

Could you tell me the regular expression to the address left only fileNames

P.S. I'm sorry, - noob. Now using code:

$s = preg_replace('/<img(.*)alt="(.*)"(.*)src="[^"]*?([^"\/]+)"/i', '<img alt="$2" src="$4"', $s);
dlbxqp
  • 11
  • 2
  • Use any html parser. – splash58 Feb 01 '19 at 12:13
  • Do not under any circumstances try to parse HTML with a regex unless you wish to invoke rite 666 read this https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 as to why *Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn.* – JGNI Feb 01 '19 at 12:25

1 Answers1

1

Just put the filename directly...

$s = <<<HD
...
<img title="blablabla" alt='blabla' src='image.jpg'>
...
<img alt="bla " src="1.png" title='blabla' />
...
<img src="img.gif">
...
HD;