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
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 їb] and ї/b]
$pattern = array("/(\їїbB]\])/", "/(\ї\/ї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 їlink="http://www.evilwalrus.com"]Evil Walrusї/link] or їlink="http://www.php.net"]php.netї/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

You might want to check out a related thread at
http://www.devnetwork.net/forums/viewtopic.php?t=1444

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