help with regex

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
untouchable
Forum Newbie
Posts: 7
Joined: Sat Jul 06, 2002 11:41 pm

help with regex

Post 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.
rd64pro
Forum Newbie
Posts: 7
Joined: Tue Jun 18, 2002 6:10 pm
Location: Sacramento, CA

Post 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
User avatar
untouchable
Forum Newbie
Posts: 7
Joined: Sat Jul 06, 2002 11:41 pm

Post 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.
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post 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
Post Reply