Last active
June 22, 2023 14:47
-
-
Save ryasmi/0fb9f6042c1e0af0d74f to your computer and use it in GitHub Desktop.
Revisions
-
ryasmi revised this gist
Jan 23, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ return preg_replace_callback($url_pattern, function (array $url_array) use ($target) { $url = implode($url_array, ''); $protocol_pattern = '/^(?:(?:https?|ftp):\/\/)/iu'; $href = preg_match($protocol_pattern, $url) ? $url : 'http://'.$url; return '<a href="'.$href.'" target="'.$target.'">'.$url.'</a>'; }, $text); }; -
ryasmi revised this gist
Jan 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ return preg_replace_callback($url_pattern, function (array $url_array) use ($target) { $url = implode($url_array, ''); $protocol_pattern = '/^(?:(?:https?|ftp):\/\/)/iu'; $href = preg_match($protocol_pattern, $text) ? $url : 'http://'.$url; return '<a href="'.$href.'" target="'.$target.'">'.$url.'</a>'; }, $text); -
ryasmi revised this gist
Jan 22, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,8 @@ return preg_replace_callback($url_pattern, function (array $url_array) use ($target) { $url = implode($url_array, ''); $protocol_pattern = '/^(?:(?:https?|ftp):\/\/)/iu' $href = preg_match($protocol_pattern, $text) ? $url : 'http://'.$url; return '<a href="'.$href.'" target="'.$target.'">'.$url.'</a>'; }, $text); }; -
ryasmi revised this gist
Jan 22, 2015 . 2 changed files with 8 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,10 @@ var wrapURLs = function (text, new_window) { var url_pattern = /(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}\-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?/ig; var target = (new_window === true || new_window == null) ? '_blank' : ''; return text.replace(url_pattern, function (url) { var protocol_pattern = /^(?:(?:https?|ftp):\/\/)/i; var href = protocol_pattern.test(url) ? url : 'http://' + url; return '<a href="' + href + '" target="' + target + '">' + url + '</a>'; }); }; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,12 @@ <?php $wrapURLs = function ($text, $new_window = true) { $url_pattern = '/(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}\-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?/iu'; $target = $new_window ? '_blank' : ''; return preg_replace_callback($url_pattern, function (array $url_array) use ($target) { $url = implode($url_array, ''); $href = preg_match('/^(?:(?:https?|ftp):\/\/)/iu', $text) ? $url : 'http://'.$url; return '<a href="'.$href.'" target="'.$target.'">'.$url.'</a>'; }, $text); }; -
ryasmi revised this gist
Jan 22, 2015 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ $wrapUrls = function ($text, $new_window = true) { $url_pattern = '/(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}\-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?/iu'; $target = $new_window ? '_blank' : ''; return preg_replace_callback($url_pattern, function (array $url_array) use ($target) { -
ryasmi revised this gist
Jan 22, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,3 +16,6 @@ Returns a String in which URLs have been replaced with anchors tag linking to th wrapURLs('Google is pretty awesome! Take a look at http://www.google.com.'); // Returns 'Google is pretty awesome! Take a look at <a href="http://www.google.com" target="_blank">http://www.google.com</a>.' ``` ## Credit The URL Regex used here is taken from @diegoperini submission at https://mathiasbynens.be/demo/url-regex. -
ryasmi revised this gist
Jan 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ Wraps all URLs in anchor tags with a `href` and `target` inside some given text. ## Parameters Name | Type | Description --- | --- | --- text | String | The text that may or may not containing URLs. new_window | Boolean | Determines if the URLs should be opened in a new window (optional - defaults to `true`). -
ryasmi revised this gist
Jan 22, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ Wraps all URLs in anchor tags with a `href` and `target` inside some given text. ## Parameters Name | Type | Description --- | --- text | String | The text that may or may not containing URLs. @@ -13,5 +14,5 @@ Returns a String in which URLs have been replaced with anchors tag linking to th ## Example ```js wrapURLs('Google is pretty awesome! Take a look at http://www.google.com.'); // Returns 'Google is pretty awesome! Take a look at <a href="http://www.google.com" target="_blank">http://www.google.com</a>.' ``` -
ryasmi renamed this gist
Jan 22, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ryasmi created this gist
Jan 22, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ # wrapURLs Wraps all URLs in anchor tags with a `href` and `target` inside some given text. ## Parameters Name | Type | Description --- | --- text | String | The text that may or may not containing URLs. new_window | Boolean | Determines if the URLs should be opened in a new window (optional - defaults to `true`). ## Returns Returns a String in which URLs have been replaced with anchors tag linking to the URL. ## Example ```js wrapURLs('Google is pretty awesome! Take a look at http://www.google.com.'); // Returns 'Google is pretty awesome! Take a look at <a href="http://www.google.com">http://www.google.com</a>.' ``` This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ var wrapURLs = function (text, new_window) { var url_pattern = /(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}\-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?/ig; var target = (new_window === true || new_window == null) ? '_blank' : ''; return text.replace(url_pattern, function (url) { return '<a href="' + url + '" target="' + target + '">' + url + '</a>'; }); }; This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ <?php $wrapUrls = function ($text, $new_window = true) { $url_pattern = '/(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}\-\x{ffff}0-9]+-?)*[a-z\x{00a1}\-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}\-\x{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?/iu'; $target = $new_window ? '_blank' : ''; return preg_replace_callback($url_pattern, function (array $url_array) use ($target) { $url = implode($url_array, ''); return '<a href="'.$url.'" target="'.$target.'">'.$url.'</a>'; }, $text); };