Skip to content

Instantly share code, notes, and snippets.

@jgwill
Last active October 29, 2018 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgwill/c5ee029be3be6ecb028210404b7885e6 to your computer and use it in GitHub Desktop.
Save jgwill/c5ee029be3be6ecb028210404b7885e6 to your computer and use it in GitHub Desktop.
PHP parsing content to format URL to become clickable in HTML
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