Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

php strpos, stripos, strpos, substr

I want to search a string for all the words with #. and then display the whole word along with the #. I'm looking at some php built in functions but I don't know where to begin and how to put them together.

ex.

I love the fault in our stars book! this is now my #favourite #book. It's better than the #movie.

I want to collect #favourite, #book and #movie and display them.

1 Answer

Hi Don,

I haven't learned about regular expressions yet so I can't give you an answer of my own but I'll try to point you in the right direction.

I think that you want to be looking at preg_match_all and a regular expression for the pattern you have.

This stackoverflow question may be a suitable answer for you or at least get you off in the right direction: http://stackoverflow.com/questions/19976571/get-hashtag-from-string-and-get-into-meta-keywords-and-tags

nice! it worked man! thanks!