Regular Expression for URLs using ereg_replace
Ever needed a Regular Expression to parse URLs in a body of text. The beauty with this expression is its flexibility, it will handle a http or https url with or without www and it’s fine with tinyurls.
[sourcecode language="php"]
// $message contains a body of text with non html URLs
$text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $message);
[/sourcecode]
$subject will be the body of text containing flat text urls. $text will now contain our information.
[sourcecode language="php"]
// Output New formatted content with links.
echo $text;
[/sourcecode]
Now our content is parsed with URLs.
Done!
PHP’s Memory Usage
This is a handy little Snippet that goes well with PHP Microtime. Not only are we concerned with our scripts execution time but we also want to make sure we are not using an exorbitant amount of memory in the process.
At the top of your script lets place the code that will start PHP’s Micro time.
[sourcecode language="php"]
$time_start = microtime(true);
[/sourcecode]
At the bottom of your page, just before the “

