Last active
October 26, 2016 10:18
-
-
Save kenjiroe/d16d5a5c123f1c59f505c22ede849c5b to your computer and use it in GitHub Desktop.
Hashtag
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 characters
| <?php | |
| function convertHashtags($str){ | |
| $regex = "/#+([a-zA-Z0-9_]+)/"; | |
| $str = preg_replace($regex, '<a href="hashtag.php?tag=$1">$0</a>', $str); | |
| return($str); | |
| } | |
| $string = "I am #UberSilly and #MegaPlayful online"; | |
| $string = convertHashtags($string); | |
| echo $string; | |
| //Usage:Fulltag | |
| if(isset($_GET["tag"])){ | |
| $tag = preg_replace('#[^a-z0-9_]#i', '', $_GET["tag"]); | |
| // $tag is now sanitized and ready for database queries here | |
| $fulltag = "#".$tag; | |
| echo $fulltag; | |
| } | |
| #https://www.developphp.com/video/PHP/Hashtag-System-and-Regex-PHP-Programming-Tutorial | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment