Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP: Finding a URL within a string and converting to hyperlink

I’m trying to find a link within a string (paragraph)(stored as a ‘text’ type in MYQSL). What would be the best approach at doing this?

For example (string from database):

$string = "Visit here: https://example.com to find more information";

I’m trying to hyperlink "https://example.com"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks in advance.

>Solution :

Using a regular expression would be your best option.

Check out the answer on this thread.

https://stackoverflow.com/questions/9151681/find-url-from-string-with-php#:~:text=following%20code%20is%20used%20to,%24text%5B0%5D%20.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading