homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

RegExp Problem

 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,



 11:50 am on Jun 25, 2010 (gmt 0)

Hi there marked,

Remove the single quotes from around the quoted variable... '$i' to just $i

Hope that helps :)

I would post the code but it keeps coming up error when I try to post :(



 12:57 pm on Jun 25, 2010 (gmt 0)

Thanks for you reply,

I tried that before, as well as many other variations. Without the single quotes I get this error: Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$'


 1:26 pm on Jun 25, 2010 (gmt 0)

Hi there marked,

Oop's try this then, I hadn't noticed this on first read ;0


The forum software won't let me post the code so just try replacing everything bewteen the braces as I have suggested. ;-p

This looks like you are trying to add the $font_sizes var to a string, in which case, that should now be fine, other than that I am stumped - it's too hot to think straight!


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved