homepage Welcome to WebmasterWorld Guest from 54.237.134.62
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
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
Marked




msg:4159104
 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.

 

Matthew1980




msg:4159131
 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 :(

Cheers,
MRb

Marked




msg:4159171
 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 '$'

Matthew1980




msg:4159186
 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

{".$font_sizes[$i]."}

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!

Cheers,
MRb

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved