This question already has an answer here:
I need regular expression that converts links in plain text to HTML links. my code is:
preg_replace('/(((f|ht){1}tps:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
'<a href="\\1" target="_blank">\\1</a>', $text);
but this expression will make the image url to href as well. so my question is how to avoid if the url is in img tag like.
The text:
https://yahoo.com this is my image <img src="https://img.com/img.jpg">
The result with my expression:<a href="https://yahoo.com">https://yahoo.com</a> this is my image <img src="<a href="https://img.com/img.jpg">https://img.com/img.jpg</a>">
i want this one <a href="https://yahoo.com">https://yahoo.com</a> this is my image <img src="http://img.com/img.jpg">
</div>