Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Converting URLs to anchor tags

Code Wizard, 12-30-2006

Using preg_replace to convert non-anchored URLs into HTML hyperlinks.

<?php
$text = "This is a link to http://www.wjgilmore.com/.";
echo preg_replace("/http://(.*)//", "<a href="${0}">${0}</a>", $text);

// from "Beginning PHP 5 and MySQL: From Novice to Professional", courtesty apress.com
?>
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions