How can the PHP code be modified to make URLs starting with "www" clickable as well, in addition to those starting with "http://"?
To make URLs starting with "www" clickable in addition to those starting with "http://", we can modify the regular expression in the PHP code to match both cases. We can update the regular expression pattern to detect URLs starting with "www" as well as "http://" and add the appropriate anchor tag around the matched URLs.
<?php
function makeClickableLinks($text) {
return preg_replace('/(http:\/\/|www\.)\S+/', '<a href="$0" target="_blank">$0</a>', $text);
}
$text = "Visit www.example.com or http://example.com for more information.";
echo makeClickableLinks($text);
?>
Related questions
-
PHP MySQL dynamic content
-
explode function PHP
-
$_POST $HTTP_POST_VARS form processing