...

View Full Version : [Regex] Keyword to URL Link



Element
08-31-2007, 10:11 PM
Hey, everyone. Long time no see, again, huh?

Well I'm back! Somewhat.

I'm looking for some help on regex, I have no idea what I'm doing when it comes to this. My ADHD/ADD (Or whatever I might have) and Dyslexia really gets at me. :mad:

Anyways, I'm basically just trying to grab one word that looks like a function, eg:
functionName() [Not-Case Sensitive]

But I can't quite get it to work. Everything likes to grab more then just one word/function. Lol.

Here is my code.



<?php

$message_text = 'Hello world, this is the nl2br() function.';

$message_text = eregi_replace('/\s\w(.*)\(\(.*)\)/i', '<a href="http://php.net/$1" title="$1() Reference">$1()</a>', $message_text);

echo $message_text;

?>

Element
09-01-2007, 05:19 PM
No help on this? I thought it might be really hard. :( Drat.

Mwnciau
09-01-2007, 06:49 PM
<?php

$message_text = 'Hello world, this is the nl2br() function.';

$message_text = preg_replace('/\s([a-zA-Z0-9_]+?)\((.*?)\)/i', ' <a href="http://php.net/$1" title="$1() Reference">$1()</a> ', $message_text);

echo $message_text;

?>

Element
09-01-2007, 06:54 PM
Thank you so much Mwnciau! Your the best! I can't even begin to tell you how much this helps!

John, our Webmaster says thank you as well, very much. :)

See it in action soon on http://pznetworks.com/forums/ !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum