Jump to content

Help to create a forum - BBCodes


gaza165

Recommended Posts

  • Replies 61
  • Created
  • Last Reply

arr = explode(message, "CODE]")

 

foreach(arr as bit){

  if(ereg("[/", bit)) {      ///////////////////// this is teh tricky bit

      bit = ereg_replace(CODE], "", bit);

      bit = ereg_replace([/, "", bit);

      bit = highlight_string(bit, true);

  }

}

<?php

$arr = explode($body, "CODE]")

foreach($arr as $bit){
         if(ereg("[/", $bit)) {      ///////////////////// this is teh tricky bit
                $bit = ereg_replace('CODE]', "", $bit);
   $bit = ereg_replace('[/', "", $bit);
                $bit = highlight_string($bit, true);
            }
} 

		echo $bit;
?>

<?php

$arr = explode($body, "CODE]")

foreach($arr as $bit){
         if(ereg("[/", $bit)) {      ///////////////////// this is teh tricky bit
                $bit = ereg_replace('CODE]', "", $bit);
   $bit = ereg_replace('[/', "", $bit);
                $bit = highlight_string($bit, true);
            }
} 

		echo $bit;
?>

 

you will need to work on it slightly and also it needs to go into a function which will return the new string so echo function(message)

so i need to encase this code into a function and get it to return $bit...

 

Also, how wrong is this function??

 

Any guidance you could offer me... I really havent got a clue.

 

sorry you dont return bit my fault

 

<?php
function parse(){

$arr = explode($body, "CODE]") // you might explode here or /] or CODE i cant rember u need to work it out on paper

foreach($arr as $bit){
         if(ereg("[/", $bit)) {      ///////////////////// this is the tricky bit you need to identify wich bits are the CODE ones
                $bit = ereg_replace('CODE]', "", $bit);    // you need to remove the reminants of /] [code etc
                $bit = ereg_replace('[/', "", $bit);
                $bit = highlight_string($bit, true); // change the whole bit in the array into the result of highlight_string u must use true in order to make it return a string
            }
} 

$message = implode($arr);

return $message
} 
?>

 

i may have put ereg_replace paramiters in the wrong orderso go to php.net and check the functions

<?php

function parse($body){

$arr = explode($body, "CODE]") // you might explode here or /] or CODE i cant rember u need to work it out on paper

foreach($arr as $bit){

if(ereg("[/", $bit)) {      ///////////////////// this is the tricky bit you need to identify wich bits are the CODE ones
$bit = ereg_replace('CODE]', "", $bit);    // you need to remove the reminants of /] [code etc
$bit = ereg_replace('[/', "", $bit);
$bit = highlight_string($bit, true); // change the whole bit in the array into the result of highlight_string u must use true in order to make it return a string
			}
		} 

$message = implode($arr);
return $message
		}	 

echo parse($body);

?>

 

says there is a problem with the foreach, any ideas??

<?php
foreach($arr as $bit){
if(ereg("[/", $bit)) {      ///////////////////// this is the tricky bit you need to identify wich bits are the CODE ones
$bit = ereg_replace("CODE]", "", $bit);    // you need to remove the reminants of /] [code etc
$bit = ereg_replace("[/", "", $bit);
$bit = highlight_string($bit, true); // change the whole bit in the array into the result of highlight_string u must use true in order to make it return a string
}
}
?>

 

this gives error

 

Warning: ereg() [function.ereg]: REG_EBRACK in /home/thedesig/public_html/blog_files/blogmore.php on line 47

CODE]

<?php
function parse($body){

$arr = explode($body, "CODE]"); // you might explode here or /] or CODE i cant rember u need to work it out on paper

foreach($arr as $bit){
           if(ereg("[/", $bit)) {     
   $bit = ereg_replace("CODE]", "", $bit); 
   $bit = ereg_replace("[/", "", $bit);
   $bit = highlight_string($bit, true); 
			}
		} 
            $message = implode($arr);
   return $message;
		}	 

echo parse($body);

?>

 

all my brackets seem to be there, can you see anything wrong??

it say regbracks cos our regular expression is wrong it things were talking reg expressions instead of [/

 

so do this

 

function parse($message){
$arr = explode($message, "CODE]"); // you might explode here or /] or CODE i cant rember u need to work it out on paper
foreach($arr as $bit){
	if(ereg("\[\/", $bit)) {      ///////////////////// this is the tricky bit you need to identify wich bits are the CODE ones
		$bit = ereg_replace("CODE]", "", $bit);    // you need to remove the reminants of /] [code etc
		$bit = ereg_replace("[/", "", $bit);
		$bit = highlight_string($bit, true); // change the whole bit in the array into the result of highlight_string u must use true in order to make it return a string
	}
}
$message = implode($arr);
    return $message;
}



$body = "ghghihjk [COD]<?php echo \"dd\"; ?> [/COD] dfgeggre"; // i mean CODE

echo parse($body);

<?php

function parse($message){
   $arr = explode($message, "code]"); // you might explode here or /] or CODE i cant rember u need to work it out on paper
   foreach($arr as $bit){
      if(ereg("\[\/", $bit)) {       ///////////////////// this is the tricky bit you need to identify wich bits are the CODE ones
         $bit = ereg_replace("code]", "", $bit);    // you need to remove the reminants of /] [code etc
         $bit = ereg_replace("[/", "", $bit);
         $bit = highlight_string($bit, true); // change the whole bit in the array into the result of highlight_string u must use true in order to make it return a string
      }
   }
   $message = implode($arr);
    return $message;
}
echo parse(nl2br(htmlentities($body)));

?>

 

all this echos out is

 

http://www.thedesignmonkeys.co.uk/blog/tokenising_a_string_in_php

 

code]

Archived

This topic is now archived and is closed to further replies.

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