garethppls Posted June 28, 2006 Share Posted June 28, 2006 I have a form but I want to disable HTML. the problem with this is the form doesn't recognise paragraph breaks. any way of doing this like on this forum.thanks, Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/ Share on other sites More sharing options...
AV1611 Posted June 28, 2006 Share Posted June 28, 2006 is your answer in one of these 3?<?php$text = '<p>Test paragraph.</p><!-- Comment --> Other text';echo strip_tags($text);echo "\n";// Allow <p>echo strip_tags($text, '<p>');?>The above example will output:Test paragraph. Other text<p>Test paragraph.</p> Other text<?php$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);echo $new; // <a href='test'>Test</a>?> <?php$str = "A 'quote' is <b>bold</b>";// Outputs: A 'quote' is <b>bold</b>echo htmlentities($str);// Outputs: A 'quote' is <b>bold</b>echo htmlentities($str, ENT_QUOTES);?> Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50466 Share on other sites More sharing options...
wildteen88 Posted June 28, 2006 Share Posted June 28, 2006 You'll want to lookinto nl2br function ie:[code]<?php$str = "this text\nhas line\nbreaks in\n it!";// convert carriage returns into line breaks (<br />)echo nl2br($str);?>[/code]Also if you want to only allow paragraph tags you can use a function called [a href=\"http://www.php.net/strip-tags\" target=\"_blank\"]strip_tags[/a]. For example:[code]<?php$str = "this text<p>is only <b>allowed</b></p>paragraphs!";// strip all tags from $str but keep < p></p>!echo strip_tags($str, '<p>');?>[/code]Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50502 Share on other sites More sharing options...
garethppls Posted June 28, 2006 Author Share Posted June 28, 2006 no I want it to detect paragraph breaks in a form without putting <p> in , just like this forum as its a forum script i'm making Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50590 Share on other sites More sharing options...
Buyocat Posted June 28, 2006 Share Posted June 28, 2006 User eregi or eregi_replace to do something like...eregi("\n\r", $string); Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50591 Share on other sites More sharing options...
garethppls Posted June 28, 2006 Author Share Posted June 28, 2006 what if \n or \r arent contained in it? Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50599 Share on other sites More sharing options...
SharkBait Posted June 28, 2006 Share Posted June 28, 2006 One thing I've noticed is that with <input type="text"> tags in HTML when they are submitted to a database (like MySQL) it will read the carriage returns and store them properly.Using echo nl2br($string); works fine when outputting what was in the database and putting in the paragraphs properly. Seems to be fine for windows/macs/un*x type plateforms.*edit ok that is cool, the forum read my input tag and displayed it hehe Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50604 Share on other sites More sharing options...
garethppls Posted June 29, 2006 Author Share Posted June 29, 2006 thanks Sharkbait will try that now Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50721 Share on other sites More sharing options...
garethppls Posted June 29, 2006 Author Share Posted June 29, 2006 yep that worked thanks sharkbait. I used nl2br before inserting it to the MYSQL but its all good :) Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50970 Share on other sites More sharing options...
wildteen88 Posted June 29, 2006 Share Posted June 29, 2006 Isn't that what I suggested in my post above? Prehaps I didnt explain it very well. Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-50985 Share on other sites More sharing options...
SharkBait Posted June 29, 2006 Share Posted June 29, 2006 [!--quoteo(post=389422:date=Jun 29 2006, 01:10 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 29 2006, 01:10 PM) [snapback]389422[/snapback][/div][div class=\'quotemain\'][!--quotec--]Isn't that what I suggested in my post above? Prehaps I didnt explain it very well.[/quote]You did, I was just agreeing with what you said :) Quote Link to comment https://forums.phpfreaks.com/topic/13124-how-to-autodetect-paragraph-breaks/#findComment-51047 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.