SpellingCow.com Forum Index SpellingCow.com
Improving forum spelling since... well not very long
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your PM'sLog in to check your PM's   Log inLog in 
Forums | Home

Messing around with some code! [BBCODE HIDE]

 
Post new topic   Reply to topic    SpellingCow.com Forum Index -> Suggestions
View previous topic :: View next topic  
Author Message
meme



Joined: 26 Sep 2004
Posts: 4

PostPosted: Wed Sep 29, 2004 12:59 pm    Post subject: Messing around with some code! [BBCODE HIDE] Reply with quote

Hi

I made a edit, 6:49 PM EDT (removed 3 substr() and made it 100% case insensitive ([BbCoDe]) from the function to speed it, not much of a speed gain, but anything removed is always better!

I have been working on a spell checker for sometime now, and I thought I would share some code with you!

Most spellcheckers, autospell, polar, wintertree, aspell, ispell give you a simple option to not spell check any text within HTML tags '<', '>' this can help to allow you to add a user or admin option to not spell check any text that is in [BBCODE] text [/BBCODE] tags!

You can just do the following....

<!-- / spell[BBCODE] text [/BBCODE]spell / -->


Before running a spell check on the text! Now this can be really hard to do because [BBCODE] can be embeded within other [BBCODE] tags!

example....

[this_quote]hi...[this_quote]bye...[/this_quote][/this_quote]


So this is why I am writing this! I have written 100(s) of scripts to do this, so I figured to maybe help you and save you some time from writing one I would share mine with you!

This one only works with PHPBB, but I have others for many other boards and webmail systems that support BBCODE style tags!


Here is how it works....

Pass the function the text that contains [BBCODE] you want to hide and spell check along with your beginning and ending 'enclose string', and it will return the text with all [BBCODE] hidden, ready to be spellchecked!

Example usage....

Code:

<?
include_once ( 'bbcode_phase.php' );

$start = '<!-- / sc';
$end = 'sc / -->';

$pell_text = bbcode_hide ( $spell_text, $start, $end );

?>


Then when your done spell checking, before the re-insert into the form, just strip $start and $end from the string....


The function....

// bbcode_phase.php

Code:

<?
function bbcode_phase ( $text, $es, $ee )
{
   $out = '';
   $f = array ();
   $x = strtolower ( $text );

   for ( $z = 0; $z < strlen ( $x ); $z++ )
   {
      if ( $x[$z] == '[' )
      {
         if ( !empty ( $f ) )
         {
            $on = $f[0];
            $oc = $f[1];
            $f = array ();
         }
         else
         {
            $on = '';
            $oc = 0;
         }

         $a = 1;
         $t = substr ( $x, ( $z + 1 ), 1 );

         if ( $t == '/' )
         {
            $a = 2;
            $t = substr ( $x, ( $z + 2 ), 1 );
         }

         switch ( $t )
         {
            case 'q':
            if ( substr ( $x, ( $z + $a ), 5 ) == 'quote' )
            {
               $f[0] = 'quote';
            }
            break;
            case 'l':
            if ( substr ( $x, ( $z + $a ), 4 ) == 'list' )
            {
               $f[0] = 'list';
            }
            break;
            case 's':
            if ( substr ( $x, ( $z + $a ), 4 ) == 'size' )
            {
               $f[0] = 'size';
            }
            break;
            case 'b':
            if ( substr ( $x, ( $z + $a ), 2 ) == 'b]' )
            {
               $f[0] = 'b';
            }
            break;
            case 'u':
            if ( substr ( $x, ( $z + $a ), 2 ) == 'u]' )
            {
               $f[0] = 'u';
            }else if ( substr ( $x, ( $z + $a ), 3 ) == 'url' )
            {
               $f[0] = 'url';
            }
            break;
            case 'c':
            if ( substr ( $x, ( $z + $a ), 4 ) == 'code' )
            {
               $f[0] = 'code';
            }else if ( substr ( $x, ( $z + $a ), 5 ) == 'color' )
            {
               $f[0] = 'color';
            }
            break;
            case 'i':
            if ( substr ( $x, ( $z + $a ), 2 ) == 'i]' )
            {
               $f[0] = 'i';
            }else if ( substr ( $x, ( $z + $a ), 3 ) == 'img' )
            {
               $f[0] = 'img';
            }
            break;
         }

         if ( !empty ( $f ) )
         {
            $f[1] = 1;

            if ( !empty ( $on ) )
            {
               if ( $a == 2 && $on == $f[0] && $f[1] == $oc )
               {
                  $feg = ( strlen ( $f[0] ) + 2 );
                  $out .= '[/' . $f[0] . ']' . $ee;
                  $f = array ();
                  $z += $feg;
               } else if ( $a == 2 && $on == $f[0] && $f[1] != $oc )
               {
                  $f[1] = ( $oc - 1 );
                  $out .= $text[$z];
               } else if ( $a == 1 && $on == $f[0] )
               {
                  $f[1] += $oc;
                  $out .= $text[$z];
               }
               else
               {
                  $f[0] = $on;
                  $f[1] = $oc;
                  $out .= $text[$z];
               }
            }
            else
            {
               $feg = strlen ( $f[0] );
               $out .= $es . '[' . $f[0];
               $z += $feg;
            }
         }
         else
         {
            $f[0] = $on;
            $f[1] = $oc;
            $out .= $text[$z];
         }
      }
      else
      {
         $out .= $text[$z];
      }
   }

   return ( $out );
}

?>



I have other ones for other BBS like VB, WBB, UBB and many more, if you would like them I will email them to you!

meme

[/code]


Last edited by meme on Wed Sep 29, 2004 5:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
nuttzy99
Site Admin


Joined: 23 May 2004
Posts: 1068

PostPosted: Wed Sep 29, 2004 2:43 pm    Post subject: Reply with quote

Hey, looks great! I'll have to play around with it Very Happy

Thanks!!
-Nuttzy Cool
_________________
<?php echo "something wicked awesome for my sig"; ?>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SpellingCow.com Forum Index -> Suggestions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group :: Spelling by SpellingCow.

SpellingCow.com Privacy Policy | blueGray theme by Nuttzy

Sponsors:
Identity Theft Protection - Compare identity theft protection services
Structured Settlements - cash for structured settlements, sell annuity, lottery winnings, and more.
Barcode Scanner Manufacturer - taiwan manufacturer of scanners, swipe card reader, serial-ethernet converter, cash drawer, and other pos devices.
Advice, help & demonstrations for sign makers - Europe's leading sign makers website
Tattoo - we are a group of tattoo enthusiasts