Fri, 17 May 2024


How to automatically detect the links in a text with PHP regular expression?

By: Peter, NetArt Media
Sun, 15 November 2020

<?

$strText = 'this is a test http://www.netartmedia.net asda';

$strText = preg_replace( '/(http|ftp)+(s)?:(//)((w|.)+)(/)?(S+)?/i', '<a href="">4</a>', $strText );

echo $strText;

?>


Category: PHP Examples
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox