Jump to content

Help me PLEASE!


Azaz

Recommended Posts

Hi everyone.

 

I have a submit form which will go through this:

 

:uglyhammer:  :uglyhammer:  :uglyhammer:

 

and if you know, when i submit that to my form, and then i use bbcode parser it will show the smiley that is related to it.. but i want to minimize my users to only allow up to 10 smileys for there signature.

 

so I need a php code to check each :nudifsduif: text and count them and if it's over 10, i can echo out a error and exit;.

 

 

Thanks...

Link to comment
Share on other sites

What are you using to replace the text? If you're using str_replace you can use the optional 4th parameter to determine how many matches were replaced. ex:

 

$smilies = array(
':uglyhammer:' => 'uglyhammer.png'
);
$count = 0;
$text = str_replace(array_keys($smilies), array_values($smilies), $text, $count);
if($count > 10) {
// too many smilies
} else {
// less than 10 smilies
}

 

Similarly, you could use preg_replace to match :anythinghere: and use the optional 3rd parameter to count the occurrences, but I think the over is a better idea because not every instance of :somethinghere: will match a smiley.

Link to comment
Share on other sites

What are you using to replace the text? If you're using str_replace you can use the optional 4th parameter to determine how many matches were replaced. ex:

 

$count = 0;
$text = str_replace(array_keys($smilies), array_values($smilies), $text, $count);
if($count > 10) {
// too many smilies
} else {
// less than 10 smilies
}

 

Similarly, you could use preg_replace to match :anythinghere: and use the optional 5th parameter to count the occurrences, but I think the over is a better idea because not every instance of :somethinghere: will match a smiley.

 

 

Okay thanks, but my parser is in a seperate file and only parsers it, so i cannot error out anything in the parser file because it wont effect what is submitting, thank u 4 ur code.

 

 

Damit, im getting a parse error, expecting `T_FUNCTION...

 

this is line:

 

$text = str_replace(array_keys($default_smileys), array_values($default_smileys), $text, $count);

 

cant find the culprit hmmmmmmmmmmmmm

 

 

This is whole parser:

 

var $default_smileys = Array(
'' => 'smile.gif', ':-)' => 'smile.gif',
'=)' => 'smile.gif', '=-)' => 'smile.gif',
'' => 'frown.gif', ':-(' => 'frown.gif',
'=(' => 'frown.gif', '=-(' => 'frown.gif',
'' => 'bigsmile.gif', ':-D' => 'bigsmile.gif',
'=D' => 'bigsmile.gif', '=-D' => 'bigsmile.gif',
''=> 'angry.gif', '>:-('=> 'angry.gif',
'>=('=> 'angry.gif', '>=-('=> 'angry.gif',
'D:' => 'angry.gif', 'D-:' => 'angry.gif',
'D=' => 'angry.gif', 'D-=' => 'angry.gif',
''=> 'evil.gif', '>:-)'=> 'evil.gif',
'>=)'=> 'evil.gif', '>=-)'=> 'evil.gif',
'>'=> 'evil.gif', '>:-D'=> 'evil.gif',
'>=D'=> 'evil.gif', '>=-D'=> 'evil.gif',
'>'=> 'sneaky.gif', '>;-)'=> 'sneaky.gif',
'>'=> 'sneaky.gif', '>;-D'=> 'sneaky.gif',
'O:)' => 'saint.gif', 'O:-)' => 'saint.gif',
'O=)' => 'saint.gif', 'O=-)' => 'saint.gif',
'' => 'surprise.gif', ':-O' => 'surprise.gif',
'=O' => 'surprise.gif', '=-O' => 'surprise.gif',
':?' => 'confuse.gif', ':-?' => 'confuse.gif',
'=?' => 'confuse.gif', '=-?' => 'confuse.gif',
':s' => 'worry.gif', ':-S' => 'worry.gif',
'=s' => 'worry.gif', '=-S' => 'worry.gif',
':|' => 'neutral.gif', ':-|' => 'neutral.gif',
'=|' => 'neutral.gif', '=-|' => 'neutral.gif',
':I' => 'neutral.gif', ':-I' => 'neutral.gif',
'=I' => 'neutral.gif', '=-I' => 'neutral.gif',
':/' => 'irritated.gif', ':-/' => 'irritated.gif',
'=/' => 'irritated.gif', '=-/' => 'irritated.gif',
':\\' => 'irritated.gif', ':-\\' => 'irritated.gif',
'=\\' => 'irritated.gif', '=-\\' => 'irritated.gif',
'' => 'tongue.gif', ':-P' => 'tongue.gif',
'=P' => 'tongue.gif', '=-P' => 'tongue.gif',
'X-P' => 'tongue.gif',
'' => 'bigeyes.gif', '8-)' => 'bigeyes.gif',
'B)' => 'cool.gif', 'B-)' => 'cool.gif',
'' => 'wink.gif', ';-)' => 'wink.gif',
'' => 'bigwink.gif', ';-D' => 'bigwink.gif',
''=> 'anime.gif', '^^;' => 'sweatdrop.gif',
'>_>'=> 'lookright.gif', '>.>' => 'lookright.gif',
''=> 'lookleft.gif', '<.<' => 'lookleft.gif',
'XD' => 'laugh.gif', 'X-D' => 'laugh.gif',
'' => 'bigwink.gif', ';-D' => 'bigwink.gif',
':3' => 'smile3.gif', ':-3' => 'smile3.gif',
'=3' => 'smile3.gif', '=-3' => 'smile3.gif',
';3' => 'wink3.gif', ';-3' => 'wink3.gif',
'<g>' => 'teeth.gif', '<G>' => 'teeth.gif',
'o.O' => 'boggle.gif', 'O.o' => 'boggle.gif',
':blue:' => 'blue.gif',
':zzz:' => 'sleepy.gif',
'<3' => 'heart.gif',
':star:' => 'star.gif',
':locked:' => 'dancinglock.gif',
':baby:' => 'baby.gif',
':hug:' => 'hug.gif',
':rofl:' => 'rofl.gif',
':sniper:' => 'sniper.gif',
':rifle:' => 'rifle.gif',
':banana:' => 'banana.gif',
':zzz:' => 'sleep4.gif',
':santa' => 'santa.gif',
'' => 'cry3.gif',
':hello:' => 'hand.gif',
':love:' => 'heart2.gif',
':kiss:' => 'kuss.gif',
':blush:' => 'blush.gif',
':wallbash:' => 'wallbash.gif',
':thumbsup:' => 'thumbsup.gif',
':uglyhammer:' => 'uglyhammer.gif',
':fume:' => 'ranting.gif',
':argue:' => 'icon_argue.gif',
':uglystupid' => 'uglystupid1.gif',
':drool:' => 'drool.gif',
':angel:' => 'angel.gif',
':flamethrower:' => 'flamethrower.gif',
':hail:' => 'hail.gif',
':headscratch:' => 'headscratch.gif',
':run:'=> 'Bolt.gif', ':RUN:' => 'Bolt.gif',
':evil:' => 'devil.gif',
':cuss:' => 'cuss.gif',
':modwork:' => 'modwork.gif',
':help:' => 'help.gif',
'' => 'ph34r.gif',
':mad:' => 'mad.gif',
//@@
'' => 'mellow.gif',
'' => 'wub.gif',
'' => 'unsure.gif',
'::' => '.gif',

':help:' => 'help.gif',
'-->' => 'icon_pointr.gif',
'<--' => 'icon_pointl.gif',

);
$text = str_replace(array_keys($default_smileys), array_values($default_smileys), $text, $count);
if($count > 10) {
echo "to many smilies";
exit;


// too many smilies
} else {



// less than 10 smilies
}

Link to comment
Share on other sites

Try:

 

$default_smileys = Array(
'' => 'smile.gif', ':-)' => 'smile.gif',
'=)' => 'smile.gif', '=-)' => 'smile.gif',
'' => 'frown.gif', ':-(' => 'frown.gif',
'=(' => 'frown.gif', '=-(' => 'frown.gif',
'' => 'bigsmile.gif', ':-D' => 'bigsmile.gif',
'=D' => 'bigsmile.gif', '=-D' => 'bigsmile.gif',
''=> 'angry.gif', '>:-('=> 'angry.gif',
'>=('=> 'angry.gif', '>=-('=> 'angry.gif',
'D:' => 'angry.gif', 'D-:' => 'angry.gif',
'D=' => 'angry.gif', 'D-=' => 'angry.gif',
''=> 'evil.gif', '>:-)'=> 'evil.gif',
'>=)'=> 'evil.gif', '>=-)'=> 'evil.gif',
'>'=> 'evil.gif', '>:-D'=> 'evil.gif',
'>=D'=> 'evil.gif', '>=-D'=> 'evil.gif',
'>'=> 'sneaky.gif', '>;-)'=> 'sneaky.gif',
'>'=> 'sneaky.gif', '>;-D'=> 'sneaky.gif',
'O:)' => 'saint.gif', 'O:-)' => 'saint.gif',
'O=)' => 'saint.gif', 'O=-)' => 'saint.gif',
'' => 'surprise.gif', ':-O' => 'surprise.gif',
'=O' => 'surprise.gif', '=-O' => 'surprise.gif',
':?' => 'confuse.gif', ':-?' => 'confuse.gif',
'=?' => 'confuse.gif', '=-?' => 'confuse.gif',
':s' => 'worry.gif', ':-S' => 'worry.gif',
'=s' => 'worry.gif', '=-S' => 'worry.gif',
':|' => 'neutral.gif', ':-|' => 'neutral.gif',
'=|' => 'neutral.gif', '=-|' => 'neutral.gif',
':I' => 'neutral.gif', ':-I' => 'neutral.gif',
'=I' => 'neutral.gif', '=-I' => 'neutral.gif',
':/' => 'irritated.gif', ':-/' => 'irritated.gif',
'=/' => 'irritated.gif', '=-/' => 'irritated.gif',
':\\' => 'irritated.gif', ':-\\' => 'irritated.gif',
'=\\' => 'irritated.gif', '=-\\' => 'irritated.gif',
'' => 'tongue.gif', ':-P' => 'tongue.gif',
'=P' => 'tongue.gif', '=-P' => 'tongue.gif',
'X-P' => 'tongue.gif',
'' => 'bigeyes.gif', '8-)' => 'bigeyes.gif',
'B)' => 'cool.gif', 'B-)' => 'cool.gif',
'' => 'wink.gif', ';-)' => 'wink.gif',
'' => 'bigwink.gif', ';-D' => 'bigwink.gif',
''=> 'anime.gif', '^^;' => 'sweatdrop.gif',
'>_>'=> 'lookright.gif', '>.>' => 'lookright.gif',
''=> 'lookleft.gif', '<.<' => 'lookleft.gif',
'XD' => 'laugh.gif', 'X-D' => 'laugh.gif',
'' => 'bigwink.gif', ';-D' => 'bigwink.gif',
':3' => 'smile3.gif', ':-3' => 'smile3.gif',
'=3' => 'smile3.gif', '=-3' => 'smile3.gif',
';3' => 'wink3.gif', ';-3' => 'wink3.gif',
'<g>' => 'teeth.gif', '<G>' => 'teeth.gif',
'o.O' => 'boggle.gif', 'O.o' => 'boggle.gif',
':blue:' => 'blue.gif',
':zzz:' => 'sleepy.gif',
'<3' => 'heart.gif',
':star:' => 'star.gif',
':locked:' => 'dancinglock.gif',
':baby:' => 'baby.gif',
':hug:' => 'hug.gif',
':rofl:' => 'rofl.gif',
':sniper:' => 'sniper.gif',
':rifle:' => 'rifle.gif',
':banana:' => 'banana.gif',
':zzz:' => 'sleep4.gif',
':santa' => 'santa.gif',
'' => 'cry3.gif',
':hello:' => 'hand.gif',
':love:' => 'heart2.gif',
':kiss:' => 'kuss.gif',
':blush:' => 'blush.gif',
':wallbash:' => 'wallbash.gif',
':thumbsup:' => 'thumbsup.gif',
':uglyhammer:' => 'uglyhammer.gif',
':fume:' => 'ranting.gif',
':argue:' => 'icon_argue.gif',
':uglystupid' => 'uglystupid1.gif',
':drool:' => 'drool.gif',
':angel:' => 'angel.gif',
':flamethrower:' => 'flamethrower.gif',
':hail:' => 'hail.gif',
':headscratch:' => 'headscratch.gif',
':run:'=> 'Bolt.gif', ':RUN:' => 'Bolt.gif',
':evil:' => 'devil.gif',
':cuss:' => 'cuss.gif',
':modwork:' => 'modwork.gif',
':help:' => 'help.gif',
'' => 'ph34r.gif',
':mad:' => 'mad.gif',
//@@
'' => 'mellow.gif',
'' => 'wub.gif',
'' => 'unsure.gif',
'::' => '.gif',

':help:' => 'help.gif',
'-->' => 'icon_pointr.gif',
'<--' => 'icon_pointl.gif'
);

 

You should have "var" before defining variables. You also had an extra comma on the end of the last element of the array.

Link to comment
Share on other sites

I think I am sorry and missed you something but this will not work because it's just the parser, and my submit doesn't go through this when submitting so there will be no way to tell my user that he can't have that many... Can I still use ur first method and just count them? but I have no arrays it's a text field im submitting... :(

 

this is the full class....

 

class BBCodeLibrary {
var $default_smileys = Array(
'' => 'smile.gif', ':-)' => 'smile.gif',
'=)' => 'smile.gif', '=-)' => 'smile.gif',
'' => 'frown.gif', ':-(' => 'frown.gif',
'=(' => 'frown.gif', '=-(' => 'frown.gif',
'' => 'bigsmile.gif', ':-D' => 'bigsmile.gif',
'=D' => 'bigsmile.gif', '=-D' => 'bigsmile.gif',
''=> 'angry.gif', '>:-('=> 'angry.gif',
'>=('=> 'angry.gif', '>=-('=> 'angry.gif',
'D:' => 'angry.gif', 'D-:' => 'angry.gif',
'D=' => 'angry.gif', 'D-=' => 'angry.gif',
''=> 'evil.gif', '>:-)'=> 'evil.gif',
'>=)'=> 'evil.gif', '>=-)'=> 'evil.gif',
'>'=> 'evil.gif', '>:-D'=> 'evil.gif',
'>=D'=> 'evil.gif', '>=-D'=> 'evil.gif',
'>'=> 'sneaky.gif', '>;-)'=> 'sneaky.gif',
'>'=> 'sneaky.gif', '>;-D'=> 'sneaky.gif',
'O:)' => 'saint.gif', 'O:-)' => 'saint.gif',
'O=)' => 'saint.gif', 'O=-)' => 'saint.gif',
'' => 'surprise.gif', ':-O' => 'surprise.gif',
'=O' => 'surprise.gif', '=-O' => 'surprise.gif',
':?' => 'confuse.gif', ':-?' => 'confuse.gif',
'=?' => 'confuse.gif', '=-?' => 'confuse.gif',
':s' => 'worry.gif', ':-S' => 'worry.gif',
'=s' => 'worry.gif', '=-S' => 'worry.gif',
':|' => 'neutral.gif', ':-|' => 'neutral.gif',
'=|' => 'neutral.gif', '=-|' => 'neutral.gif',
':I' => 'neutral.gif', ':-I' => 'neutral.gif',
'=I' => 'neutral.gif', '=-I' => 'neutral.gif',
':/' => 'irritated.gif', ':-/' => 'irritated.gif',
'=/' => 'irritated.gif', '=-/' => 'irritated.gif',
':\\' => 'irritated.gif', ':-\\' => 'irritated.gif',
'=\\' => 'irritated.gif', '=-\\' => 'irritated.gif',
'' => 'tongue.gif', ':-P' => 'tongue.gif',
'=P' => 'tongue.gif', '=-P' => 'tongue.gif',
'X-P' => 'tongue.gif',
'' => 'bigeyes.gif', '8-)' => 'bigeyes.gif',
'B)' => 'cool.gif', 'B-)' => 'cool.gif',
'' => 'wink.gif', ';-)' => 'wink.gif',
'' => 'bigwink.gif', ';-D' => 'bigwink.gif',
''=> 'anime.gif', '^^;' => 'sweatdrop.gif',
'>_>'=> 'lookright.gif', '>.>' => 'lookright.gif',
''=> 'lookleft.gif', '<.<' => 'lookleft.gif',
'XD' => 'laugh.gif', 'X-D' => 'laugh.gif',
'' => 'bigwink.gif', ';-D' => 'bigwink.gif',
':3' => 'smile3.gif', ':-3' => 'smile3.gif',
'=3' => 'smile3.gif', '=-3' => 'smile3.gif',
';3' => 'wink3.gif', ';-3' => 'wink3.gif',
'<g>' => 'teeth.gif', '<G>' => 'teeth.gif',
'o.O' => 'boggle.gif', 'O.o' => 'boggle.gif',
':blue:' => 'blue.gif',
':zzz:' => 'sleepy.gif',
'<3' => 'heart.gif',
':star:' => 'star.gif',
':locked:' => 'dancinglock.gif',
':baby:' => 'baby.gif',
':hug:' => 'hug.gif',
':rofl:' => 'rofl.gif',
':sniper:' => 'sniper.gif',
':rifle:' => 'rifle.gif',
':banana:' => 'banana.gif',
':zzz:' => 'sleep4.gif',
':santa' => 'santa.gif',
'' => 'cry3.gif',
':hello:' => 'hand.gif',
':love:' => 'heart2.gif',
':kiss:' => 'kuss.gif',
':blush:' => 'blush.gif',
':wallbash:' => 'wallbash.gif',
':thumbsup:' => 'thumbsup.gif',
':uglyhammer:' => 'uglyhammer.gif',
':fume:' => 'ranting.gif',
':argue:' => 'icon_argue.gif',
':uglystupid' => 'uglystupid1.gif',
':drool:' => 'drool.gif',
':angel:' => 'angel.gif',
':flamethrower:' => 'flamethrower.gif',
':hail:' => 'hail.gif',
':headscratch:' => 'headscratch.gif',
':run:'=> 'Bolt.gif', ':RUN:' => 'Bolt.gif',
':evil:' => 'devil.gif',
':cuss:' => 'cuss.gif',
':modwork:' => 'modwork.gif',
':help:' => 'help.gif',
'' => 'ph34r.gif',
':mad:' => 'mad.gif',
//@@
'' => 'mellow.gif',
'' => 'wub.gif',
'' => 'unsure.gif',
'::' => '.gif',

':help:' => 'help.gif',
'-->' => 'icon_pointr.gif',
'<--' => 'icon_pointl.gif'
);
$count = 0;
$text = str_replace(array_keys($default_smileys), array_values($default_smileys), $text, $count);
if($count > 10) {
echo "to many smilies";
exit;


// too many smilies
} else {



// less than 10 smilies
}
var $default_tag_rules = Array(
'b' => Array(
'simple_start' => "<b>",
'simple_end' => "</b>",
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
'plain_start' => "<b>",
'plain_end' => "</b>",
),
'i' => Array(
'simple_start' => "<i>",
'simple_end' => "</i>",
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
'plain_start' => "<i>",
'plain_end' => "</i>",
),
'u' => Array(
'simple_start' => "<u>",
'simple_end' => "</u>",
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
'plain_start' => "<u>",
'plain_end' => "</u>",
),
'mp3' => Array(
'mode' => BBCODE_MODE_ENHANCED,
'template' => '<embed type="application/x-shockwave-flash" src="mp3.swf" flashvars="m={$_content/v}" width="200" height="12">',
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
'youtube' => Array(
'mode' => BBCODE_MODE_ENHANCED,
'template' => '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/{param}"></param><embed src="http://www.youtube.com/v/{$_content/v}" type="application/x-shockwave-flash" width="425" height="350"></embed></object>',
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
's' => Array(
'simple_start' => "<strike>",
'simple_end' => "</strike>",
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
'plain_start' => "<i>",
'plain_end' => "</i>",
),
'font' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'allow' => Array('_default' => '/^[a-zA-Z0-9._ -]+$/'),
'method' => 'DoFont',
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
'color' => Array(
'mode' => BBCODE_MODE_ENHANCED,
'allow' => Array('_default' => '/^#?[a-zA-Z0-9._ -]+$/'),
'template' => '<span style="color:{$_default/tw}">{$_content/v}</span>',
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
'size' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'allow' => Array('_default' => '/^[0-9.]+$/D'),
'method' => 'DoSize',
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
'sup' => Array(
'simple_start' => "<sup>",
'simple_end' => "</sup>",
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
'sub' => Array(
'simple_start' => "<sub>",
'simple_end' => "</sub>",
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
'spoiler' => Array(
'simple_start' => "<span class=\"bbcode_spoiler\">",
'simple_end' => "</span>",
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
'acronym' => Array(
'mode' => BBCODE_MODE_ENHANCED,
'template' => '<span class="bbcode_acronym" title="{$_default}">{$_content/v}</span>',
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
),
'url' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'method' => 'DoURL',
'class' => 'link',
'allow_in' => Array('listitem', 'block', 'columns', 'inline'),
'content' => BBCODE_REQUIRED,
'plain_start' => "<a href=\"{\$link}\">",
'plain_end' => "</a>",
'plain_content' => Array('_content', '_default'),
'plain_link' => Array('_default', '_content'),
),
'email' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'method' => 'DoEmail',
'class' => 'link',
'allow_in' => Array('listitem', 'block', 'columns', 'inline'),
'content' => BBCODE_REQUIRED,
'plain_start' => "<a href=\"mailto:{\$link}\">",
'plain_end' => "</a>",
'plain_content' => Array('_content', '_default'),
'plain_link' => Array('_default', '_content'),
),
'wiki' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'method' => "DoWiki",
'class' => 'link',
'allow_in' => Array('listitem', 'block', 'columns', 'inline'),
'end_tag' => BBCODE_PROHIBIT,
'content' => BBCODE_PROHIBIT,
'plain_start' => "<b>[",
'plain_end' => "]</b>",
'plain_content' => Array('title', '_default'),
'plain_link' => Array('_default', '_content'),
),
'img' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'method' => "DoImage",
'class' => 'image',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
'end_tag' => BBCODE_REQUIRED,
'content' => BBCODE_REQUIRED,
'plain_start' => "[image]",
'plain_content' => Array(),
),
'rule' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'method' => "DoRule",
'class' => 'block',
'allow_in' => Array('listitem', 'block', 'columns'),
'end_tag' => BBCODE_PROHIBIT,
'content' => BBCODE_PROHIBIT,
'before_tag' => "sns",
'after_tag' => "sns",
'plain_start' => "\n-----\n",
'plain_end' => "",
'plain_content' => Array(),
),
'br' => Array(
'mode' => BBCODE_MODE_SIMPLE,
'simple_start' => "<br />\n",
'simple_end' => "",
'class' => 'inline',
'allow_in' => Array('listitem', 'block', 'columns', 'inline', 'link'),
'end_tag' => BBCODE_PROHIBIT,
'content' => BBCODE_PROHIBIT,
'before_tag' => "s",
'after_tag' => "s",
'plain_start' => "\n",
'plain_end' => "",
'plain_content' => Array(),
),
'left' => Array(
'simple_start' => "\n<div class=\"bbcode_left\" style=\"text-align:left\">\n",
'simple_end' => "\n</div>\n",
'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns",
'after_tag' => "sns",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n",
'plain_end' => "\n",
),
'right' => Array(
'simple_start' => "\n<div class=\"bbcode_right\" style=\"text-align:right\">\n",
'simple_end' => "\n</div>\n",
'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns",
'after_tag' => "sns",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n",
'plain_end' => "\n",
),
'center' => Array(
'simple_start' => "\n<center>\n",
'simple_end' => "\n</center>\n",
'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns",
'after_tag' => "sns",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n",
'plain_end' => "\n",
),
'indent' => Array(
'simple_start' => "\n<div class=\"bbcode_indent\" style=\"margin-left:4em\">\n",
'simple_end' => "\n</div>\n",
'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns",
'after_tag' => "sns",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n",
'plain_end' => "\n",
),
'columns' => Array(
'simple_start' => "\n<table class=\"bbcode_columns\"><tbody><tr><td class=\"bbcode_column bbcode_firstcolumn\">\n",
'simple_end' => "\n</td></tr></tbody></table>\n",
'class' => 'columns',
'allow_in' => Array('listitem', 'block', 'columns'),
'end_tag' => BBCODE_REQUIRED,
'content' => BBCODE_REQUIRED,
'before_tag' => "sns",
'after_tag' => "sns",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n",
'plain_end' => "\n",
),
'nextcol' => Array(
'simple_start' => "\n</td><td class=\"bbcode_column\">\n",
'class' => 'nextcol',
'allow_in' => Array('columns'),
'end_tag' => BBCODE_PROHIBIT,
'content' => BBCODE_PROHIBIT,
'before_tag' => "sns",
'after_tag' => "sns",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n",
'plain_end' => "",
),
'code' => Array(
'mode' => BBCODE_MODE_ENHANCED,
'template' => "\n<div class=\"bbcode_code\">\n<div class=\"code2\">Code:</div>\n<div class=\"bbcode_code_body\" style=\"white-space:pre\">{\$_content/v}</div>\n</div>\n",
'class' => 'code2',
'allow_in' => Array('listitem', 'block', 'columns'),
'content' => BBCODE_VERBATIM,
'before_tag' => "sns",
'after_tag' => "sn",
'before_endtag' => "sn",
'after_endtag' => "sns",
'plain_start' => "\n<b>Code:</b>\n",
'plain_end' => "\n",
),
'quote' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'method' => "DoQuote",
'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns",
'after_tag' => "sns",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n<b>Quote:</b>\n",
'plain_end' => "\n",
),
'list' => Array(
'mode' => BBCODE_MODE_LIBRARY,
'method' => 'DoList',
'class' => 'list',
'allow_in' => Array('listitem', 'block', 'columns'),
'before_tag' => "sns",
'after_tag' => "sns",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n",
'plain_end' => "\n",
),
'*' => Array(
'simple_start' => "<li>",
'simple_end' => "</li>\n",
'class' => 'listitem',
'allow_in' => Array('list'),
'end_tag' => BBCODE_OPTIONAL,
'before_tag' => "s",
'after_tag' => "s",
'before_endtag' => "sns",
'after_endtag' => "sns",
'plain_start' => "\n * ",
'plain_end' => "\n",
),
);

function DoURL($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK) return true;
$url = is_string($default) ? $default : $bbcode->UnHTMLEncode(strip_tags($content));
if ($bbcode->IsValidURL($url)) {
if ($bbcode->url_targetable !== false && isset($params['target']))
$target = " target=\"" . htmlspecialchars($params['target']) . "\"";
else $target = "";
if ($bbcode->url_target !== false)
if (!($bbcode->url_targetable == 'override' && isset($params['target'])))
$target = " target=\"" . htmlspecialchars($bbcode->url_target) . "\"";
return '<a href="' . htmlspecialchars($url) . '" class="bbcode_url"\'target="blank"\'>' . $content . '</a>';
}
else return htmlspecialchars($params['_tag']) . $content . htmlspecialchars($params['_endtag']);
}
function DoEmail($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK) return true;
$email = is_string($default) ? $default : $bbcode->UnHTMLEncode(strip_tags($content));
if ($bbcode->IsValidEmail($email))
return '<a href="mailto:' . htmlspecialchars($email) . '" class="bbcode_email">' . $content . '</a>';
else return htmlspecialchars($params['_tag']) . $content . htmlspecialchars($params['_endtag']);
}
function DoSize($bbcode, $action, $name, $default, $params, $content) {
switch ($default) {
case '0': $size = '.5em'; break;
case '1': $size = '.67em'; break;
case '2': $size = '.83em'; break;
default:
case '3': $size = '1.0em'; break;
case '4': $size = '1.17em'; break;
case '5': $size = '1.5em'; break;
case '6': $size = '2.0em'; break;
case '7': $size = '2.5em'; break;
}
return "<span style=\"font-size:$size\">$content</span>";
}
function DoFont($bbcode, $action, $name, $default, $params, $content) {
$fonts = explode(",", $default);
$result = "";
$special_fonts = Array(
'serif' => 'serif',
'sans-serif' => 'sans-serif',
'sans serif' => 'sans-serif',
'sansserif' => 'sans-serif',
'sans' => 'sans-serif',
'cursive' => 'cursive',
'fantasy' => 'fantasy',
'monospace' => 'monospace',
'mono' => 'monospace',
);
foreach ($fonts as $font) {
$font = trim($font);
if (isset($special_fonts[$font])) {
if (strlen($result) > 0) $result .= ",";
$result .= $special_fonts[$font];
}
else if (strlen($font) > 0) {
if (strlen($result) > 0) $result .= ",";
$result .= "'$font'";
}
}
return "<span style=\"font-family:$result\">$content</span>";
}
function DoWiki($bbcode, $action, $name, $default, $params, $content) {
$name = $bbcode->Wikify($default);
if ($action == BBCODE_CHECK)
return strlen($name) > 0;
$title = trim(@$params['title']);
if (strlen($title) <= 0) $title = trim($default);
return "<a href=\"{$bbcode->wiki_url}$name\" class=\"bbcode_wiki\">"
. htmlspecialchars($title) . "</a>";
}
function DoImage($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK) return true;
$content = trim($bbcode->UnHTMLEncode(strip_tags($content)));
if (preg_match("/\\.(?:gif|jpeg|jpg|jpe|png)$/", $content)) {
if (preg_match("/^[a-zA-Z0-9_][^:]+$/", $content)) {
if (!preg_match("/(?:\\/\\.\\.\\/)|(?:^\\.\\.\\/)|(?:^\\/)/", $content)) {
$info = @getimagesize("{$bbcode->local_img_dir}/{$content}");
if ($info[2] == IMAGETYPE_GIF || $info[2] == IMAGETYPE_JPEG || $info[2] == IMAGETYPE_PNG) {
return "<img src=\""
. htmlspecialchars("{$bbcode->local_img_url}/{$content}") . "\" alt=\""
. htmlspecialchars(basename($content)) . "\" width=\""
. htmlspecialchars($info[0]) . "\" height=\""
. htmlspecialchars($info[1]) . "\" class=\"bbcode_img\" />";
}
}
}
else if ($bbcode->IsValidURL($content, false)) {
return "<img src=\"" . htmlspecialchars($content) . "\"/>";
}
}
return htmlspecialchars($params['_tag']) . htmlspecialchars($content) . htmlspecialchars($params['_endtag']);
}
function DoRule($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK) return true;
else return $bbcode->rule_html;
}
function DoQuote($bbcode, $action, $name, $default, $params, $content) {
if ($action == BBCODE_CHECK) return true;
if (isset($params['name'])) {
$title = htmlspecialchars(trim($params['name'])) . " wrote";
if (isset($params['date']))
$title .= " on " . htmlspecialchars(trim($params['date']));
$title .= ":";
if (isset($params['url'])) {
$url = trim($params['url']);
if ($bbcode->IsValidURL($url))
$title = "<a href=\"" . htmlspecialchars($params['url']) . "\">" . $title . "</a>";
}
}
else if (!is_string($default))
$title = "Quote:";
else $title = htmlspecialchars(trim($default)) . " wrote:";
return "<div class=\"quote1\">"
. $title . "<bR>"
. $content . "</div>";
}
function DoList($bbcode, $action, $name, $default, $params, $content) {
$list_styles = Array(
'1' => 'decimal',
'01' => 'decimal-leading-zero',
'i' => 'lower-roman',
'I' => 'upper-roman',
'a' => 'lower-alpha',
'A' => 'upper-alpha',
);
$ci_list_styles = Array(
'circle' => 'circle',
'disc' => 'disc',
'square' => 'square',
'greek' => 'lower-greek',
'armenian' => 'armenian',
'georgian' => 'georgian',
);
$ul_types = Array(
'circle' => 'circle',
'disc' => 'disc',
'square' => 'square',
);
$default = trim($default);
if ($action == BBCODE_CHECK) {
if (!is_string($default) || strlen($default) == "") return true;
else if (isset($list_styles[$default])) return true;
else if (isset($ci_list_styles[strtolower($default)])) return true;
else return false;
}
if (!is_string($default) || strlen($default) == "") {
$elem = 'ul';
$type = '';
}
else if ($default == '1') {
$elem = 'ol';
$type = '';
}
else if (isset($list_styles[$default])) {
$elem = 'ol';
$type = $list_styles[$default];
}
else {
$default = strtolower($default);
if (isset($ul_types[$default])) {
$elem = 'ul';
$type = $ul_types[$default];
}
else if (isset($ci_list_styles[$default])) {
$elem = 'ol';
$type = $ci_list_styles[$default];
}
}
if (strlen($type))
return "\n<$elem class=\"bbcode_list\" style=\"list-style-type:$type\">\n$content</$elem>\n";
else return "\n<$elem class=\"bbcode_list\">\n$content</$elem>\n";
}
}

 

 

I still get

Parse error: parse error, expecting `T_FUNCTION' in C:\wamp\www\nbbc.php on line 464

 

and That line is:

$count = 0;

 

Sorry for the trouble, but if you could find a way, it would be wonderful, thanks.

Link to comment
Share on other sites

If you don't have a choice you can validate the input the way you initially wanted to before it goes to the parser. Something like this should work:

 

$matches = array();
preg_match_all('~.+?):~', $text, $matches);
if(sizeof($matches[0]) > 10) {
// too many
}

Link to comment
Share on other sites

EDIT: Oh jeeze, maybe it's to late but is there anyway I can do the same thing with your script but use it to count fensifni

 

I was thinking like this:

 

preg_match_all('~[youtube](.+?)[/youtube]~', $_POST['Post'], $matches);

 

That is out of the ordinary but I was wondering if it's possible, I have not tested do to the fact that I am very anxious in learning this first, thanks.

 

Sorry for the double post.

Link to comment
Share on other sites

Yeah, you can do that but you're pattern will have to be a bit different. In regex [ and ] are special characters so you'll need to escape them.

 

preg_match_all('~\[youtube\](.+?)\[/youtube\]~', $_POST['Post'], $matches);

Link to comment
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.