Gruzin Posted July 26, 2006 Share Posted July 26, 2006 Hope u guys can help me, I've got a problem:I've got a form where I input some text, but I cann't make a space between lines (kind of paragraph); please help me, I really need this :'(Here is the code:<?php $link = "admin.php"; $linkShow = "Your info is saved"; $text = stripslashes($_POST["text"]); $text_file = "text/homepage.txt"; $name_gax = file($text_file); //opens with array $text_open = fopen($text_file, "w+"); //open message file with write fputs($text_open, $text); fclose($text_open); echo "<a href='".$link."'>".$linkShow;?> Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/ Share on other sites More sharing options...
ozPATT Posted July 26, 2006 Share Posted July 26, 2006 this any good?[code]$text = stripslashes (preg_replace(array("/\r?\n\r?\n/","/\r\n/"),array("</p>\n\n<p>","<br />\n"),$_POST['text']));[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64026 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 thanks man :) can u explain me how does it work? Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64030 Share on other sites More sharing options...
ozPATT Posted July 26, 2006 Share Posted July 26, 2006 if only i could! haha, it is a piece of code that I acquired some time ago, and uses regular expressions. Basically, it replaces any line returns from the textarea, with the paragraph and break tags that html uses. eg\r\n is one line break or return. so that should be <br />. two of them, equal a paragraph, which is <p></p>.Pretty clever really. Did it do what you wanted? Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64033 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 Why not just use nl2br()? Alot simpler. Does the samething.nl2br converts any newline characters (\r\n, \r, \n) to < br /> (without the space before the br). Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64034 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 ye I've done it! you"ve saved me ozPATT, cheers mate:) Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64035 Share on other sites More sharing options...
ozPATT Posted July 26, 2006 Share Posted July 26, 2006 is that a predefined function? never heard of it. glad to help Gruzin Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64037 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 nl2br has been around since PHP3. Check it out [url=http://uk2.php.net/manual/en/function.nl2br.php]here[/url] Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64040 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 wildteen88 do u mean something like this?$text = stripslashes (nl2br($_POST['text']));it doesn't work...... Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64042 Share on other sites More sharing options...
kenrbnsn Posted July 26, 2006 Share Posted July 26, 2006 [quote]it doesn't work[/quote]covers a lot of ground. What doesn't work? What did you expect?I would do the functions is this order:[code]<?php $text = nl2br(stripslashes($_POST['text'])); ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64044 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 remove stripslashes. Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64045 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 it works, why remove srtipslashes?Thanks guys:) Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64054 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 Beacuase it intefere with nl2br and the whitepace characters (\n, \r, etc). Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64060 Share on other sites More sharing options...
kenrbnsn Posted July 26, 2006 Share Posted July 26, 2006 That's why I suggested to reverse the order of the functions.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64069 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 ok, another question if I won't distrub you:when I input the text and need to write bold text or link it, how can I do that?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64073 Share on other sites More sharing options...
kenrbnsn Posted July 26, 2006 Share Posted July 26, 2006 You need to output the correct HTML tags along with the text.For bolding:(the old way)[code]<?php echo '<b>' . $text . '</b>'; ?>[/code](the new way)[code]<?php echo '<span style="font-weight:bold">' . $text . '</span>'; ?>[/code]To create a link:[code]<?php echo '<a href="http://url.goes.here/">' . $text . '</a>'; ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64077 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 thanks a lot, everyday I find out something new on this great forum:) Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64079 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 how can I make a form like in this forum, when u click a button text becomes bold or u make it linked? Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64087 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 somebody please help:( Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64099 Share on other sites More sharing options...
wildteen88 Posted July 26, 2006 Share Posted July 26, 2006 This is called BBCode. Search google for BBCode Inserter or something like that. It requires javascript. But to replace the BBCodes ie [ b]hello[/b] in to [b]hello[/b] will require the use of regular expressions. [url=http://www.phpfreaks.com/forums/index.php/topic,101566.msg402102.html#msg402102]Here[/url] is a very basic BBCode Parser, it parses bold, italic and underline BBCode. Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64100 Share on other sites More sharing options...
Gruzin Posted July 26, 2006 Author Share Posted July 26, 2006 thanks, I'll try that:) Quote Link to comment https://forums.phpfreaks.com/topic/15692-urgent-help-needed/#findComment-64103 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.