Jump to content

BB-Codes question


bachx

Recommended Posts

Hello, I've made a BB-code script, but I'm wondering about one thing. I want to have a maximum allowed size when using .

 

Here is a sample code snippet of my bbcode script:

 

function format_bbcodes($text) {

$text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is",'<span style="font-size: $1px">$2</span>',$text);

return $text;
}

Link to comment
https://forums.phpfreaks.com/topic/62639-bb-codes-question/
Share on other sites


function format_bbcodes($text) {

return preg_replace("(\[size=(.+?)\](.+?)\[\/size\])ies","'<span style=\"font-size: '.max($1,20).'px\">$2</span>'",$text);

}

 

Works quite well...

 

Adding the 'e' switch means the replacement is treated as a PHP expression, hence being able to put a bit of code in there... if you wanted to do further validation, you could use:

 

function splat($size =10) {
return ($size > 20) ? 20 : $size;
}
function format_bbcodes($text) {

return preg_replace("(\[size=(.+?)\](.+?)\[\/size\])ies","'<span style=\"font-size: '.max($1,20).'px\">$2</span>'",$text);
}

 

 

Where splat has extra checks applied to it.

 

Swapping the size=(.+?)\ for size=(\d{1,2})\ would be a good plan

Link to comment
https://forums.phpfreaks.com/topic/62639-bb-codes-question/#findComment-311773
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.