[Nottingham] PHP RegEx woes

Christopher Joice linuxisthefuture at gmail.com
Fri Oct 3 17:32:34 UTC 2008

I'm trying to do what I think should be a very simple find, crop, and
pad exercise in php.
What I want to do is this:

     1. Find a string which is surrounded by [[ and ]]
     2. replace [[ with <a href="foo.bar.co.uk/
     3. put in the string
     4. put in ">
     5. put in the string, again, so it shows up in the html output
     6. replace the ]] with </a>

I've got a regex which can do this, BUT it's a greedy little bugger so
only works if there is only one instance in the text, which just doesn't

$page['content'] = ereg_replace("\[\[(.*)]]",
		     '<a href="'.$site["url"].'/page/\\1">\\1</a>', $page['content']);

I've tried putting some ?s in there to try and make it lazy, but get
REG_BADRPT errors, so I must be putting it in the wrong place?

Any help appreciated, I've been going around in circles trying to work
this one out, and I've not found anything on the 'net that is of use.

Christopher Joice
"May the forces of evil become confused on the way to your house."
-- George Carlin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/nottingham/attachments/20081003/ac35d3d6/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://mailman.lug.org.uk/pipermail/nottingham/attachments/20081003/ac35d3d6/attachment.pgp 

More information about the Nottingham mailing list