Skip to content

Instantly share code, notes, and snippets.

@iedmrc
Created July 14, 2016 01:26
Show Gist options
  • Save iedmrc/8e778a522652c12b6cd877cb22555b4e to your computer and use it in GitHub Desktop.
Save iedmrc/8e778a522652c12b6cd877cb22555b4e to your computer and use it in GitHub Desktop.
//$message herhangi bir string olmak uzere hashtagler, mentionlar,youtube linkleri ve normal linkler icin preg.
$parsedMessage =
preg_replace_callback_array(
[
'/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))/'
=>function ($m) {
$matches=[];
$match_bool=preg_match('/\s*[a-zA-Z\/\/:\.]*youtu(be.com\/watch\?v=|.be\/)([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i',$m[0],$matches);
if($match_bool)
{
return '<iframe src="//www.youtube.com/embed/'.$matches[2].'" type="text/html" width="480" height="270" allowfullscreen></iframe>';
}
else
{
return '<a href="'.$m[1].'" target="_blank">'.$m[1].'</a>';
}
},
'/(^|[^a-z0-9_])@([a-z0-9_]+)/i'
=>function ($m) {
if (!User::where('username', $m[2])->exists())
{
return $m[1].'<a href="/'.$m[2].'">@'.$m[2].'</a>';
}
},
'/(^|[^a-z0-9_])#([a-z0-9şŞıİçÇöÖüÜĞğ_]+)/i'
=>function ($m) {return $m[1].'<a href="/hashtag/'.$m[2].'">#'.$m[2].'</a>';}
],
$message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment