Jump to content

PHP Regular Expression


cheatasp

Recommended Posts

I am assuming there is more text in the string than just a URL, other wise preg_replace is useless, anyways give this a try:

<?php
$str = 'Hello this is my url www.mysite.com check it out!';

echo $new = preg_replace('~(www\..*|http://.*)\s~','<a href="$1">$1</a>');
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.