Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- RegExp Problem


Marked - 10:37 am on Jun 25, 2010 (gmt 0)


I'm trying to make a simple bbcode system, but I'm having a little issue with inserting a variable from the regexp expression into an array.

Here's the code:


$font_sizes = array(1 => 9,
2 => 13,
3 => 15,
4 => 17,
5 => 21,
6 => 26,
7 => 36 );

$pattern[2] = '#\[size="(.+?)"\](.+?)\[/size\]#is';
$replacements[2] = "[size={$font_sizes['$1']}]$2[/size]";

$post = preg_replace($pattern, $replacements, $post);


As you can see, I want size used in the bbcode to change based on the array. But the I can't get it working in this line:
$replacements[2] = "[size={$font_sizes['$1']}]$2[/size]";

Anyone got any ideas?

Thanks in advance,
Mark.


Thread source:: http://www.webmasterworld.com/php/4159102.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com