php - Find and convert symbol to anchors -



php - Find and convert symbol to anchors -

sorry if question duplicate of ones, couldn't find :-/

hey guys, guessing it's simple regexp question help me out you? regexps complicated me :-)

in illustration :

@2 lorem ipsum dolor sit down amet, consectetur adipiscing elit. praesent sit down amet quam ante, sit down amet consectetur ante. ut non urna in quam adipiscing consectetur et sed lorem. donec venenatis vehicula porttitor.

i want convert @2 to

<a href="#2">@2</a>

but user may type "@2lorem.." without space or may @38427. how can grab '@' symbol , numbers after , convert anchor?

edit: , @ may in middle of text may not in beginning.

preg_replace('/@(\d+)/', '<a name="#$1">@$1</a>', $string)

sample:

php > $x = 'abc @234lorem def'; php > echo preg_replace('/@(\d+)/', '<a name="#$1">@$1</a>', $x); abc <a name="#234">@234</a>lorem def \d - digit + - 1 or more times

php regex anchor

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -