...

View Full Version : Need Help With This Code



OnTheCoffee
05-10-2004, 11:22 PM
function functionrenamed( $str ){

$str = explode( ' ', $str );

$num = count( $str );

$codeon = false;

for( $i = 0; $i < $num; $i++ ){

if( $codeon == false ){

if( ereg( "\[", $str[$i] ) ){

$str_cur = explode( '[', $str[$i] );

#
#

if( ereg( "]", $str_cur[1] ) ){

#

$str_cur_1 = explode( ']', $str_cur[1] );

#
#

$code = $str_cur_1[0];

switch( $code ){
default:
$code_op = "[$code]";
break;
case 'b':
$code_op = '<b>';
break;
case 'i':
$code_op = '<i>';
break;
case 'img':
$code_op = '<img src="';
break;
}

$codeon = true;

$str[$i] = $str_cur[0] . $code_op . $str_cur_1[1];

}

}

}
elseif( $codeon == true ){

if( ereg( "\[/", $str[$i] ) ){

$str_cur = explode( '[/', $str[$i] );

#
#

if( ereg( "]", $str_cur[1] ) ){

#

$str_cur_1 = explode( ']', $str_cur[1] );

#
#

$code = $str_cur_1[0];

switch( $code ){
default:
$code_cl = "[/$code]";
break;
case 'b':
$code_cl = '</b>';
break;
case 'i':
$code_cl = '</i>';
break;
case 'img':
$code_cl = '">';
break;
}

$codeon = false;

$str[$i] = $str_cur[0] . $code_cl . $str_cur_1[1];

}

}

}

$str_c .= "$str[$i] ";

}

return $str_c;

}



Can anyone tell me what this code does?

sad69
05-11-2004, 12:42 AM
Few things:

this isn't Javascript, it looks like Perl or PHP -- so wrong forum (DOM??)
this looks like homework: professor gives you some code, asks you what it does and to give the function a meaningful name. I don't think we're supposed to do people's homework here: (http://www.codingforums.com/showthread.php?t=2090)
what's the input? it's not impossible to figure out what this function does without the input, but it'd be a lot easier if we knew.
wrap your code in [ code ] [ /code ] tags (no spaces) and format it so it's readable -- you'll get a better response


Good luck,
Sadiq.

sidney
05-11-2004, 01:37 AM
it looks like it replaces bbcode tags with html tags



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum