Daleeburg Posted February 23, 2007 Share Posted February 23, 2007 I am trying to make a BBCode deal here and am running into some problems attempting to make a link code. The hope is to make a way so that my user can type in {url=xxxxxxx}yyyyyy{/url} (imagine brackets where the {} are) and they get out the <a href="xxxxxxxxx">yyyyyyyyyy< /a> or if they put in {url}yyyyyy{/url} (imagine brackets where the {} are) they get <a href="yyyyyyyy">yyyyyyyyy< /a> I found this snipped of code on the interwebz and did not think it would work, but i tried it anyways (it didnt work ) (parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')') $BBCode = array( '/\[url\=(.*?)\](.*?)\[\/url\]/is' => '<a href="$1">$2</a>' ); $text = str_replace(array_keys($BBCode), array_values($BBCode), $_POST['body']); (there is more to the array then this, but this is the problem line) So if anybody knows how to make this work, or a way to do this and would please share, it would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/39819-homebrew-bbcode/ Share on other sites More sharing options...
darkcarnival Posted February 23, 2007 Share Posted February 23, 2007 heres a post i posted about in another forum: http://programmingtalk.com/showthread.php?t=15388 it really helped me Link to comment https://forums.phpfreaks.com/topic/39819-homebrew-bbcode/#findComment-192356 Share on other sites More sharing options...
Daleeburg Posted February 23, 2007 Author Share Posted February 23, 2007 tried that, and now it wont post at all, i even tried commenting out and all i get is an did not post message, the variables come out fine though. <?php FUNCTION addentry(){ IF(ISSET($_SESSION['user'])){ // function BBCode($string, $allowimgs = false) { // $from[] = '~\[i\](.*?)\[\/i\]~is'; // $from[] = '~\[b\](.*?)\[\/b\]~is'; // $from[] = '~\[u\](.*?)\[\/u\]~is'; // $from[] = '~\[s\](.*?)\[\/s\]~is'; // $from[] = '~\[url=(.*?)\](.*?)\[\/url\]~is'; // $from[] = '~\[url\](.*?)\[\/url\]~is'; // $from[] = '~\[center\](.*?)\[\/center\]~is'; // $from[] = '~\[right\](.*?)\[\/right\]~is'; // $from[] = '~\[left\](.*?)\[\/left\]~is'; // $to[] = '<i>\\1</i>'; // $to[] = '<b>\\1</b>'; // $to[] = '<u>\\1</u>'; // $to[] = '<del>\\1</del>'; // $to[] = '<a href="\\1">\\2</a>'; // $to[] = '<a href="\\1">\\1</a>'; // $to[] = '<div align="center">\\1</div>'; // $to[] = '<div align="right">\\1</div>'; // $to[] = '<div align="left">\\1</div>'; // we don't want to allow imgs all the time! // if ($allowimgs == true) { // $from[] = '~\[img\](.*?)\[\/img\]~is'; // $to[] = '<img src="\\1" border="0" alt="" />'; // }; // $string = preg_replace($from, $to, $string); // return $string; // }; $text = $_POST['body']; //$text = BBCode($text, true); $date = date(DATE_RFC822); $body = nl2br($text); $title = $_POST['title']; $user = $_SESSION['user']; $query = 'insert into '.$_SESSION['accessdb'].' (title, body, date, who) values (\"'.$title.'\",\"'.$body.'\",\"'.$date.'\",\"'.$_SESSION['user'].'\")'; $result = mysql_query($query) OR DIE("Did Not Post<br>".$_SESSION['accessdb']." <br> $title <br> $body <br> $date <br> $user "); ECHO 'You have Succefuly Posted! One Moment for the Redirection. <a href=editor.php?mode=2"> Click here </a> If the page does not reload in 15 seconds <meta http-equiv="refresh" content="2; url=editor.php?mode=2" />'; }ELSE{ECHO "Please Log in";} }; ?> Link to comment https://forums.phpfreaks.com/topic/39819-homebrew-bbcode/#findComment-192382 Share on other sites More sharing options...
boo_lolly Posted February 23, 2007 Share Posted February 23, 2007 take a look at this solved topic, it may help you... http://www.phpfreaks.com/forums/index.php/topic,127886.msg534191.html#msg534191 Link to comment https://forums.phpfreaks.com/topic/39819-homebrew-bbcode/#findComment-192390 Share on other sites More sharing options...
Daleeburg Posted February 23, 2007 Author Share Posted February 23, 2007 k i have nailed down my submit problem but i ran into a new one when i try to use the URL commands or the left, center or right for some reason my database will not accept it, any other command works and if i put in the html by hand it works. here is the code <?php FUNCTION addentry(){ IF(ISSET($_SESSION['user'])){ function BBCode($string, $allowimgs = false) { $from[] = '~\[i\](.*?)\[\/i\]~is'; $from[] = '~\[b\](.*?)\[\/b\]~is'; $from[] = '~\[u\](.*?)\[\/u\]~is'; $from[] = '~\[s\](.*?)\[\/s\]~is'; $from[] = '~\[url=(.*?)\](.*?)\[\/url\]~is'; $from[] = '~\[url\](.*?)\[\/url\]~is'; $from[] = '~\[center\](.*?)\[\/center\]~is'; $from[] = '~\[right\](.*?)\[\/right\]~is'; $from[] = '~\[left\](.*?)\[\/left\]~is'; $to[] = '<i>\\1</i>'; $to[] = '<b>\\1</b>'; $to[] = '<u>\\1</u>'; $to[] = '<del>\\1</del>'; $to[] = '<a href="\\1">\\2</a>'; $to[] = '<a href="\\1">\\1</a>'; $to[] = '<div align="center">\\1</div>'; $to[] = '<div align="right">\\1</div>'; $to[] = '<div align="left">\\1</div>'; //we don't want to allow imgs all the time! if ($allowimgs == true) { $from[] = '~\[img\](.*?)\[\/img\]~is'; $to[] = '<img src="\\1" border="0" alt="" />'; }; $string = preg_replace($from, $to, $string); return $string; }; $text = $_POST['body']; $text = BBCode($text, true); $date = date(DATE_RFC822); $body = nl2br($text); $title = $_POST['title']; $query = 'insert into '.$_SESSION['accessdb'].' (title, body, date, who) values ("'.$title.'","'.$body.'","'.$date.'","'.$_SESSION['user'].'")'; $result = mysql_query($query) OR DIE("Did Not Post <br> $body "); ECHO 'You have Succefuly Posted! One Moment for the Redirection. <a href=editor.php?mode=2"> Click here </a> If the page does not reload in 15 seconds <meta http-equiv="refresh" content="2; url=editor.php?mode=2" />'; }ELSE{ECHO "Please Log in";} }; ?> so the real question is, do i convert it to html before it is put in the database, or do you convert it right before it is viewed? Link to comment https://forums.phpfreaks.com/topic/39819-homebrew-bbcode/#findComment-192474 Share on other sites More sharing options...
darkcarnival Posted February 23, 2007 Share Posted February 23, 2007 the idea is to convert when your drawing out the data from the db. this is the easiest way to do it and also allows you to do some necessary cleaning and so forth. Link to comment https://forums.phpfreaks.com/topic/39819-homebrew-bbcode/#findComment-192494 Share on other sites More sharing options...
Daleeburg Posted February 23, 2007 Author Share Posted February 23, 2007 hopefully the last question. using the PHP from above when i use the link bb for some reason it adds http://localhost/xxxxxxxxx to all of my links, any clue how to stop this? Link to comment https://forums.phpfreaks.com/topic/39819-homebrew-bbcode/#findComment-192513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.