nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 i was wrong you can use highlight_string(string, true) to return a string so therfore you can actualy replace the part of the message and therfore keep the whole message string intact. Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675678 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 If someone could write the code out i will implement into my system then upload it to the web.. Â Â Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675679 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 Use arrays? Explode at the tags? Â true true Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675680 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 If someone could write the code out i will implement into my system then upload it to the web.. Â Â Â il write you a psudo and you can write it yourself, consider urself lucky Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675681 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 lol thankyou very much... Â I really have no idea where to start with constructing this new code... you will really need to help me out.. I am a total noob and not ashamed to admit it Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675682 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 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);  } } Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675687 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 im sorry if some of the function paramiters are the wrong way around Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675690 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 <?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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675695 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 <?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) Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675700 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675702 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675708 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 function parse($body){ Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675721 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 <?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?? Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675740 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 yes you need a ; Â $arr = explode($body, "CODE]") ; Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675741 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 and here return $message; Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675743 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 Warning: ereg() [function.ereg]: REG_EBRACK in /home/thedesig/public_html/blog_files/blogmore.php on line 47 CODE] Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675744 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 $bit = ereg_replace("CODE]", "", $bit);Â Â // you need to remove the reminants of /] [code etc $bit = ereg_replace("[/", "", $bit); Â change the ' ' into " " Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675747 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 <?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] Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675749 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 REG_EBRACKÂ means brackets ntio ballanced check make sure ur not missing any brackets Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675753 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 <?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?? Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675757 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675775 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 if(ereg("\[\/", $bit)) { Â its talkign about the brackets in the regular expression because [a-z] means somthing in regular expressions so if you whant a [ you have to backslash it out \[ and same with / has to be \/ Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675779 Share on other sites More sharing options...
gaza165 Posted October 27, 2008 Author Share Posted October 27, 2008 <?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] Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675782 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 you will also need to incorperate  $p1 = strpos($text, "<CODE>", $p2); $p2 = strpos($text, "CODE>", $p1+strlen("<CODE>")); $list = substr($text, $p1, $p2 - $p1); Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675784 Share on other sites More sharing options...
nadeemshafi9 Posted October 27, 2008 Share Posted October 27, 2008 i have the finished code here but i wont give you it cos its not mine to give Quote Link to comment https://forums.phpfreaks.com/topic/130247-help-to-create-a-forum-bbcodes/page/2/#findComment-675786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.