I need to convert
$text = 'We had <i>fun</i>. Look at <a href="http://example.com">this photo</a> of Joe';
[Edit] There could be multiple links in the text.
to
$text = 'We had fun. Look at this photo (http://example.com) of Joe';
All HTML tags are to be removed and the href value from <a> tags needs to be added like above.
What would be an efficient way to solve this with regex? Any code snippet would be great.
First do a preg_replace to keep the link. You could use:
Then use
strip_tagswhich will finish off the rest of the tags.