Need help with preg_replace

Joined: 11/28/2008

I've been hard at work the past month or so updating SMF's IPB2 converter so it will work with IPB 2.1, and am almost finished with it. The converter uses preg_replace and a couple of arrays to replace IPB's code with the appropriate bbcode tag - the first array contains the pattern syntax to match the various things, and the second array contains the corresponding bbcode tag (for example, <!--coloro:blue--><span style="color:blue"><!--/coloro--> gets replaced with [color]). However, I'm having trouble matching the smilie code. I've already tried modifying the pattern syntax for images, and no matter what I try, nothing seems to work.

Here's an example of what I need to match:

CODE
<img src="style_emoticons/<#EMO_DIR#>/angry017.gif" style="vertical-align:middle" emoid=":angry017:" border="0" alt="angry017.gif" />

Having recently deleted my XP-powered virtual machine in favor of one powered by Linux (Fedora Core 5), I was eager to test out the KRegExp Editor that comes with the kdewebdev package, so I tried building the pattern with that, and even that didn't work.

Can anyone help me out here? I've got several people eagerly awaiting this converter and would like to get it done soon...

Michael "Oldiesmann" Eshom
SMF Webmaster

Joined: 11/28/2008
so the only thing that would

so the only thing that would change between them is the 'angry017'?

TJ SINGLETON

Joined: 11/28/2008
That and the value of

That and the value of "emoid". I would just assume that emoid could be anything, not necessarily :filename:

Michael "Oldiesmann" Eshom
SMF Webmaster

Joined: 11/28/2008
This is a super simple

This is a super simple version tested only on the string you gave, so I am not prmosing this is a catch all anything here...

CODE
<?php
$pttrn = "/<img src=\"style_emoticons\/<#EMO_DIR#>\/[^\"]+\" style=\"vertical-align:middle\" emoid=\":[^:]+:\" border=\"0\" alt=\"[^\"]+\" \/>/";

$str = "<img src=\"style_emoticons/<#EMO_DIR#>/angry017.gif\" style=\"vertical-align:middle\" emoid=\":angry017:\" border=\"0\" alt=\"angry017.gif\" />";

preg_match_all($pttrn,$str,$theMatches);

var_dump($theMatches);

?>

Joined: 11/28/2008
CODE <?php$pattern = '<img
CODE
<?php
$pattern = '<img src="style_emoticons/<#EMO_DIR#>/[A-Za-z0-9]*\.gif" style="vertical-align:middle" emoid=":[A-Za-z0-9]*:" border="0" alt="[A-Za-z0-9]*\.gif" />';
$replace = 'smile';
$string = '<img src="style_emoticons/<#EMO_DIR#>/angry017.gif" style="vertical-align:middle" emoid=":angry017:" border="0" alt="angry017.gif" />';
echo preg_replace($pattern, $replace, $string);
?>

Here is my super-simple one, but it assumes the smiley will be a gif.

TJ SINGLETON

Joined: 11/28/2008
I'll try it when I get a

I'll try it when I get a chance. Thanks!

Michael "Oldiesmann" Eshom
SMF Webmaster

Joined: 11/28/2008
You'll need ( around each of

You'll need () around each of the matching bits won't you?

CODE
<?php
$pttrn = "/<img src=\"style_emoticons\/<#EMO_DIR#>\/([^\"]+)\" style=\"vertical-align:middle\" emoid=\":([^:]+):\" border=\"0\" alt=\"[^\"]+\" \/>/";

$str = "<img src=\"style_emoticons/<#EMO_DIR#>/angry017.gif\" style=\"vertical-align:middle\" emoid=\":angry017:\" border=\"0\" alt=\"angry017.gif\" />";

preg_match_all($pttrn,$str,$theMatches);

var_dump($theMatches);

?>

This should work for any extension (as Jim's does, since I started from his). But it should return the bits you want as separate match items due to the use of the ().

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified