Saturday 15 May 2010

regex - Parse text for hashtags and replace with links using php -


I have some text with twitter style # hashtag. How do I write a function to parse a part of the text In which unlimited number can be #hashtags, take the text of the hashtag and replace them with and

I have thought a lot about how I have done this but I am really bad in writing these works with regex.

Example text:

Advertisement for advertising Vivamus #tristique Non elit eu iaculis Vivamus eget ultricies neither Maurice Contemporary Scalarisk Doniic resident Maury, Pulvinar and Vivamous Hunderet # Once again, she tells about the different types of life she is going to get a chance for #Comodo A, Port and Tales Deuce Eaget Advance Gravidy, Camille Agu Id, Blend Lectus Francesella. Donec EGT Port Epsom # Maurice Sad Maurice AG Dexterity power donic a # opitium # ogu, ejet hendratat orci

attempt to use it Do:

  $ text = "dispute #trustic non elite euakulis."; $ Text = preg_replace ('/ # (\ w +) /', '& lt; a href = "tag / $ 1" & gt; $ 1 & lt; / a & gt;', $ text); // $ text now: Vivaamas & lt; A href = "tags / tricks" & gt; Tristol & lt; / A & gt; Non elite EU ecclesiastes;   

Here it is working: (click run).

Original Source:

No comments:

Post a Comment