0
<div class="media_embed" height="qqq" width="www">
<a href="http://giphy.com/gifs/dancing">via GIPHY</a>
<div class="media_embed" height="eee" width="rrr">
<a href="http://giphy.com/gifs/movie">via GIPHY</a>

i want to do this: i have to get de href from anchor tag and put it bewtween img tags and add figure tag

<figure>
  <img src="http://giphy.com/gifs/dancing" />
</figure>
<figure>
  <img src="http://giphy.com/gifs/movie" />
</figure>

can you please help me

Mohammad
  • 21,175
  • 15
  • 55
  • 84
skycomputer2
  • 243
  • 1
  • 13

1 Answers1

0

The best solution is parsing html and then change it. You can use DOMDocument to parse html. But if you want to use regex, use preg_replace() to replace a tag with another tag.

echo preg_replace("/<a href=\"(.*)\">.*<\/a>/", "<figure><img src='$1' /></figure>", $html)

Check result in demo

Mohammad
  • 21,175
  • 15
  • 55
  • 84