Reply to hide bbcode for spell checking!

Your name:

Reply:


Posted by "Sonia" on 07/30/05 20:58

This is what it needs to do!

The first tag that is found will set where the parser will insert '<!-- /
sc' before that tag. Any bbcode tags that are in the current tag will be
skipped over until the parser finds the end of the current bbcode tag it is
working on. Once it finds the end of the current tag it will insert 'sc
/ -->' after the end of the current tag. It will continue doing this until
no tags are left to be parsed in the string!


My script is below....

My question...

Is there a better way to do this?


// script!

<?

$res = array ( '<!-- / sc', 'sc / -->', '', '' );

$str = "[quote=tinyman,Jul 29 2005, 11:27 PM]

Visit my site www.site.com . It provide Email Service(4gb), Free Forum, Free
File Hosting, Free Webhosting and Free Blog hosting.

[b][right]149013[/right][/b]

[/quote][email][b]mm@mm.com[/b][/email][code]<? echo 'hi';

?>[/code]



jp

";

echo bbcode_phase ( $str, $res[0], $res[1] );

function bbcode_phase ( $text, $es, $ee )

{

$bb = array ( 'q' => '5|quote',

'r' => '5|right',

'e' => '5|email',

'h' => '4|html',

'p' => '3|php',

'f' => '4|font',

'l' => array ( '4|list', '4|left' ),

's' => '4|size', 'b' => array ( '2|b]|b', '5|bible' ),

'u' => array ( '2|u]|u', '3|url' ),

'c' => array ( '4|code', '5|color', '6|center' ),

'i' => array ( '2|i]|i', '3|img', '6|indent' ) );



$a = ''; // the output string holder

$b = array (); // the current tag info array

$c = 0; // where we are in the substr

$d = strtolower ( $text ); // lower case the string

while ( ( $e = strpos ( $d, '[' ) ) !== false )

{

$a .= substr ( $text, $c, $e );

$c += $e;

/* if we have a current tag do this */

if ( ! empty ( $b ) )

{

/* if we match the end of the current tag process it */

if ( substr ( $d, ( $e + 2 ), $b[0] ) == $b[1] )

{

if ( isset ( $b[2] ) ) // for bbcode tags ([b], [i] ... )

{

$a .= '[/' . strtoupper ( $b[2] ) . ']' . $ee;

$c += ( $b[0] + 2 );

$d = substr ( $d, ( $e + $b[0] + 2 ) );

}

else

{

$a .= '[/' . strtoupper ( $b[1] ) . ']' . $ee;

$c += ( $b[0] + 3 );

$d = substr ( $d, ( $e + $b[0] + 3 ) );

}

$b = array ();

}

else /* not a current tag substr 1 character forward */

{

$a .= substr ( $text, $c, 1 );

$d = substr ( $d, ( $e + 1 ) );

$c += 1;

}

}

else /* no current tag, find one if it is there */

{

$f = false;

$g = substr ( $d, ( $e + 1 ), 1 );

if ( isset ( $bb[$g] ) )

{

/*

* some tags have more than 1 value so they

* are arrays other are just string values.

*/

if ( is_array ( $bb[$g] ) )

{

for ( $i = 0; $i < sizeof ( $bb[$g] ); $i++ )

{

$b = explode ( '|', $bb[$g][$i] );

if ( substr ( $d, ( $e + 1 ), $b[0] ) == $b[1] )

{

$f = true;

break;

}

}

}

else

{

$b = explode ( '|', $bb[$g] );

if ( substr ( $d, ( $e + 1 ), $b[0] ) == $b[1] )

{

$f = true;

}

}

}

/* we have found a starting tag process it */

if ( $f )

{

if ( isset ( $b[2] ) ) // for bbcode tags ([b], [i] ... )

{

$a .= $es . '[' . strtoupper ( $b[2] );

$c += $b[0];

$d = substr ( $d, ( $e + $b[0] ) );

}

else

{

$a .= $es . '[' . strtoupper ( $b[1] );

$c += ( $b[0] + 1 );

$d = substr ( $d, ( $e + 1 + $b[0] ) );

}

}

else /* not a good starting tag substr 1 character forward */

{

$a .= substr ( $text, $c, 1 );

$b = array ();

$d = substr ( $d, ( $e + 1 ) );

$c += 1;

}

}

}

/*

* if the string has more characters after the last

* closing tag put back what is left...

*

*/

if ( ! empty ( $d ) )

{

$a .= substr ( $text, $c );

}

return ( $a );

}

?>


thanks

Sonia

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация