Last active
October 29, 2018 18:35
-
-
Save jgwill/c5ee029be3be6ecb028210404b7885e6 to your computer and use it in GitHub Desktop.
PHP parsing content to format URL to become clickable in HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach ($chatDatas as $chat) | |
{ | |
//Expression capturing URL string | |
$urlXpression = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i'; | |
//replacing in text URL with formatted HTML Linked Tag | |
$chatHTML = preg_replace($urlXpression, '<a href="$0" target="_blank" title="$0">$0</a>', $chat); | |
//display each chat element | |
echo "<tr><td>" | |
. $chatHTML["ChatLine"] | |
. "</td></tr>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment