0

I have strings:

$string1 = 'Hi John. Please, go to my website http://www.google.com :)'; $string2 = 'See this :P www.imgurl.com/abcd.jpg'; 

How can I convert this strings to:

$string1 = 'Hi John. Please, go to my website <a href="http://www.google.com">http://www.google.com</a> :)'; $string2 = 'See this :P <img src="http://www.imgurl.com/abcd.jpg" alt ="" />'; 

I dont know ;(

0

1 Answer 1

0

The best approach will be to use a regular expression to replace your URL with either the <a> Tag or the <img> Tag. The tricky part will be to determine whether it is an image or a normal URL.

Read here about PHP preg_replace function: https://www.php.net/preg_replace

And here is a list of regular expressions to match URLs: http://regexlib.com/Search.aspx?k=url&AspxAutoDetectCookieSupport=1

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.