SirChick Posted December 24, 2007 Share Posted December 24, 2007 I was wondering.. say a user wants to bold something in a forum: Some have: [b]Test[/b] then html uses: <b>Test</b> Now how do you make it so user input "allows" [b][/b] etc and also means when the text is echo'd it will be [b]bold[/b] ? Is it all done in html or is php involved too ? Will string escape function disallow it or does it allow it? Link to comment https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/ Share on other sites More sharing options...
papaface Posted December 24, 2007 Share Posted December 24, 2007 <strong>text</strong> Not sure what you mean ??? Link to comment https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/#findComment-422106 Share on other sites More sharing options...
SirChick Posted December 24, 2007 Author Share Posted December 24, 2007 LOL my bad i put bold tags around it and forgot the code tags so it was just making the font bold so i guess it must of made me look a bit odd. Re-corrected now. Link to comment https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/#findComment-422109 Share on other sites More sharing options...
papaface Posted December 24, 2007 Share Posted December 24, 2007 PHP is involved. It is bbcode. Search on google for it. Link to comment https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/#findComment-422111 Share on other sites More sharing options...
marcus Posted December 24, 2007 Share Posted December 24, 2007 <?php function bbcode_format($post) { $post = htmlentities($post); $simple_search = array( '/\[b\](.*?)\[\/b\]/is' ); $simple_replace = array( '<strong>$1</strong>' ); // Do simple BBCode's $post = preg_replace ($simple_search, $simple_replace, $post); return $post; } $post = "[b]hello[/b]"; $p = bbcode_format($post); echo $post."<br>"; echo $p."<br>"; ?> Link to comment https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/#findComment-422112 Share on other sites More sharing options...
SirChick Posted December 24, 2007 Author Share Posted December 24, 2007 <?php $simple_search = array( '/\[b\](.*?)\[\/b\]/is' ); $simple_replace = array( '<strong>$1</strong>' ); ?> Could you explain this part a bit... not sure i follow what thats doing ? Is it like a way to stop injection with bbcode ? Link to comment https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/#findComment-422114 Share on other sites More sharing options...
marcus Posted December 24, 2007 Share Posted December 24, 2007 It's escaping the brackets to be correct format for regex. Then if [b]text[/b] is found somewheres in the variable, it will replace it with the strong HTML. Link to comment https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/#findComment-422115 Share on other sites More sharing options...
SirChick Posted December 24, 2007 Author Share Posted December 24, 2007 Ok thankyou very much Link to comment https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/#findComment-422118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.