Twitist Forums
A script that detects hashtags in PHP? - Printable Version

+- Twitist Forums (http://twitist.com)
+-- Forum: Twitter forums (/forum-1.html)
+--- Forum: Twitter Hashtag (/forum-2.html)
+--- Thread: A script that detects hashtags in PHP? (/thread-37281.html)



A script that detects hashtags in PHP? - Josh Davis - 11-09-2012 08:52 PM

Anybody know how I could create a script that detects hashtags(like twitter) so during the submit script it would find any #then a word. Please help, send me a link to a tutorial or explain how; I know basic php. I'm still learning.


- Gitlez - 11-09-2012 09:00 PM

You are going to want to look into php's regular expressions, or regex. This will do what you are looking for. Some people find it complicated at the beginning, but once you understand them, then they become an indispensable tool. Just be careful not to over use them. They are resource heavy and many developers use them in place of inherit string functions. This is a mistake. Learn what the proper uses are for them, and what is simply a waste of resources.


Cheers,

Gitlez


- David Harris - 11-09-2012 09:00 PM

I dunno.
Something like

$match = preg_match('/#/',$yourvariable);
if($match) {
//do something here
} else {
//do something else here
}
maybe?