Page 1 of 1

help with regex

Posted: Wed Jul 10, 2002 11:12 pm
by untouchable
Hi, I was trying to do a little ereg_replace for my news system i was making. Does anyone here have a solution because regular expressions really tip my teacup :cry:

All i want to do is transform (b)Hello(/b) into hello

of course i will use brackets not parenthesis. thanks for your help.

Posted: Wed Jul 10, 2002 11:59 pm
by rd64pro
Here's an example that should suit your purposes...

Code: Select all

// the string to evaluate
$strtoeval = 'їb]Manї/b]... this regex stuff smells like їb]Doodieї/b]!';

// the strings to replace їb] and ї/b] with
$replace = array("<b>", "</b>");

// the string that match &#1111;b] and &#1111;/b]
$pattern = array("/(\&#1111;&#1111;bB]\])/", "/(\&#1111;\/&#1111;bB]\])/");

print preg_replace($pattern, $replace, $strtoeval);
What this does search the string twice; once for and once for . Ideally, you would come up with a dynamic replace string that would insert tokens instead of hard-coded values, but if you're just doing these two tags, you get the idea.

Let me know if I completely misinterpreted your question...

-Ryan

Posted: Thu Jul 11, 2002 4:30 pm
by untouchable
this solution would indeed work. The problem is, what if i want to do things like [link="http://www.php.net"]PHP4. Making sure of course, that the can be followed by anything and that i can do things like

Code: Select all

I suggest you visit &#1111;link="http://www.evilwalrus.com"]Evil Walrus&#1111;/link] or &#1111;link="http://www.php.net"]php.net&#1111;/link] for more help.
When I tried to code something like this, this would happen: EvilWalrus[/link] or [link="http://www.php.net"]php.net or something to that effect.

Posted: Thu Jul 11, 2002 11:53 pm
by gnu2php
:arrow: You might want to check out a related thread at http://www.devnetwork.net/forums/viewtopic.php?t=1444

:arrow: You can also see some source code I posted on that thread at http://www.devnetwork.net/forums/viewto ... =1444#7194