Issue
I have written these codes to convert url-like text to hyperlink:
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/www\.[a-zA-Z0-9]{5}\.com(\w*)(\/\S*)?/";
echo preg_replace($reg_exUrl, '<a href="$1://www.$2.com">$1://www.$2.com$3</a>','http://www.abcde.com/index.html');
Output is :
<a href="http://www..com">http://www..com/index.html</a>
But $2 is empty - why is this?
Solution
I think you want something like this:
(http|https|ftp|ftps)\:\/\/www\.([a-zA-Z0-9]{5})\.com(\w*\/\S*)?
https://regex101.com/r/MJ3A6K/1
Answered By - amasmiller Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.