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. 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.. 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 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 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 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); } } 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 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; ?> 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) 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. 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 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){ 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?? 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]") ; 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; 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] 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 " " 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] 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 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?? 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); 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 \/ 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] 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); 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 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
Archived
This topic is now archived and is closed to further replies.