Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.