Baez Posted June 10, 2010 Share Posted June 10, 2010 I'm submitting a form to another page. Once it gets to the second page, it does a few replacements and displays the form data from the textarea. I can't seem to match newlines properly though. Here's the code: $data = preg_replace("/\n|\r/", "<br/>", $_POST['data']); It matches nothing and displays the newlines as spaces. Quote Link to comment Share on other sites More sharing options...
Alex Posted June 10, 2010 Share Posted June 10, 2010 Use nl2br. Quote Link to comment Share on other sites More sharing options...
Baez Posted June 10, 2010 Author Share Posted June 10, 2010 Thanks. Tried it but it's still displaying as a space and not replacing anything. I used it like so: $data = nl2br($_POST['data']); Example, this is what would be in the textarea field: Form Data And this is what it displays on the next page: Form Data Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 10, 2010 Share Posted June 10, 2010 $data = nl2br($_POST['data']); That doesn't work? Quote Link to comment Share on other sites More sharing options...
Alex Posted June 10, 2010 Share Posted June 10, 2010 Please post your exact code. That should work, but you could be making another mistake; for example, echoing out $_POST['data'] instead of $data. Quote Link to comment Share on other sites More sharing options...
Baez Posted June 10, 2010 Author Share Posted June 10, 2010 $descrip = nl2br($_SESSION['descriptemp']); $descrip = preg_replace("/\[b\]/", "<strong>", $_SESSION['descriptemp']); $descrip = preg_replace("/\[\/b\]/", "</strong>", $_SESSION['descriptemp']); $pageShowGuide = new Page(); $pageShowGuide->incpath = "../../"; $pageShowGuide->sidebar = ""; $pageShowGuide->title = $_SESSION['titletemp']; $pageShowGuide->content = " <div id=\"wide_main\"> <div id=\"guide_summ_".$_SESSION['colortemp']."\"> <div id=\"guide_pic\"> <img src=\"images/game/".$type."/".$img."\" /> </div> ".$descrip." </div> <h1>".$_SESSION['titletemp']."</h1> </div>"; $pageShowGuide->showPage(); In the page before, the SESSION variables are set from the raw POST data. The reason I'm using a second page is the first determines which submit button was pressed and continues from there. If you need any other code I'll post it up. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 10, 2010 Share Posted June 10, 2010 $descrip = nl2br($_SESSION['descriptemp']); $pageShowGuide = new Page(); $pageShowGuide->incpath = "../../"; $pageShowGuide->sidebar = ""; $pageShowGuide->title = $_SESSION['titletemp']; $pageShowGuide->content = " <div id=\"wide_main\"> <div id=\"guide_summ_".$_SESSION['colortemp']."\"> <div id=\"guide_pic\"> <img src=\"images/game/".$type."/".$img."\" /> </div> ".$descrip." </div> <h1>".$_SESSION['titletemp']."</h1> </div>"; $pageShowGuide->showPage(); you don't need preg_replace with nl2br Quote Link to comment Share on other sites More sharing options...
Baez Posted June 10, 2010 Author Share Posted June 10, 2010 The other two preg_replaces are for BBCode not newlines. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 10, 2010 Share Posted June 10, 2010 I'm blind some times. Sorry. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 10, 2010 Share Posted June 10, 2010 It's not working because you're doing this <?php $descrip = nl2br($_SESSION['descriptemp']); $descrip = preg_replace("/\[b\]/", "<strong>", $_SESSION['descriptemp']); $descrip = preg_replace("/\[\/b\]/", "</strong>", $_SESSION['descriptemp']); ?> instead of <?php $descrip = nl2br($_SESSION['descriptemp']); $descrip = preg_replace("/\[b\]/", "<strong>", $descrip); $descrip = preg_replace("/\[\/b\]/", "</strong>",$descrip); ?> Notice the difference? You could also do <?php $descrip = str_replace(array('[b]','[/b]'),array('<strong>','</strong>'),$descrip); ?> instead of the two preg_replace() functions. Ken Quote Link to comment Share on other sites More sharing options...
Baez Posted June 10, 2010 Author Share Posted June 10, 2010 Thanks Ken that does help but it still doesn't solve the newline problem. Quote Link to comment Share on other sites More sharing options...
Alex Posted June 10, 2010 Share Posted June 10, 2010 Did you read what he said? It should. Quote Link to comment Share on other sites More sharing options...
Baez Posted June 10, 2010 Author Share Posted June 10, 2010 Ah okay I read through it thoroughly but I was thinking a different way the first time. From what I saw the revised code was simply looking at the edited version of the description and replacing the BBCode with HTML. I wasn't looking at it as replacing the entire value on the second line. I'm not new to PHP by any means but sometimes we just make these ridiculous errors! Great thanks for all your help guys Quote Link to comment 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.