working from the inside out

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

working from the inside out

Post by HiddenS3crets »

I have the following regex comparison that replaces any [*]content[/*] with <*>content</*>

Code: Select all

<?php
$pattern = "/\[link\=(.+?)\](.+?)\[\/link\]/is";
$replacement = "<a href=\'$1\'>$2</a>";
?>
I was wondering if there's a way to modify this code so it will match when you do multiple tags such as: [*][*]content[/*][/*] so it will convert both sets of [] with <>
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: working from the inside out

Post by prometheuzz »

You mean you want to replace a String like:

Code: Select all

[ b][link="http://www.google.com"]Google[/link][ /b]
with

Code: Select all

<b><a href="http://www.google.com">Google</a></b>
where all kind of html tags and attributes can be used, then the answer is: no, there is no easy way to do this with regex.
Post Reply