UltraMarkus Posted June 30, 2013 Share Posted June 30, 2013 Hi, First post on this form for me now. Love to see how many posts are made on this site. Well after searching a few hours my problem remains and started to look for some help. Here is what I do: 1. Read a textarea with val() and send it trough ajax. 2. In my php file I send the data to a DB. 3. I read the db and uses nl2br to make this all seem worth it. But now there is a funny thing happening, i can see no next lines(breaks). So what did I do, I used to replace all /n/l things to <BR /> with some repeace function. But now when i echo my little tekst there is just a simple <BR /> beeing displayed. Anyone knows someting about this problem? UltraMarkus. Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/ Share on other sites More sharing options...
UltraMarkus Posted July 3, 2013 Author Share Posted July 3, 2013 It was like all conversions were done to : "<" = "<" and ">" = ">" Just converted them $message = str_replace("<","<",$message);$message = str_replace(">",">",$message); Hope it helps someone. UltraMarkus Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/#findComment-1439337 Share on other sites More sharing options...
Irate Posted July 4, 2013 Share Posted July 4, 2013 Why not just echo "<br />" in your script and be done with it? PHP natively supports HTML (when used in servers, not on the cli). Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/#findComment-1439370 Share on other sites More sharing options...
UltraMarkus Posted July 4, 2013 Author Share Posted July 4, 2013 $("#bericht").val().replace(/\n/g,"<br>") this is send to my ajax request. And the above convertion is created. If i leave the /n/l then i use nl2br in php and nothing happens either Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/#findComment-1439477 Share on other sites More sharing options...
Csharp Posted July 4, 2013 Share Posted July 4, 2013 You probably have got some point of the script that converts them into < Could you post a bigger bit of script of what you're doing? And what the DB contains? Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/#findComment-1439487 Share on other sites More sharing options...
UltraMarkus Posted July 5, 2013 Author Share Posted July 5, 2013 ------------------------------------------ Send form ------------------------------------------ function adSubmit() { ajax_request("berichtPlaatsen.php?table=te_koop_aangeboden&naam="+$("#naam").val()+"&email="+$("#email").val()+"&bericht="+$("#bericht").val().replace(/\n/g,"<br>"),"#adToevoegen",berichtGeplaatst); } <form> textarea id="bericht" name="bericht" style="width:99%; height:200px">bericht</textarea><input id="submitButton" type="button" onclick="adSubmit()" value="Plaatsen" > </form> ------------------------------------------- When displaying ------------------------------------------- $bericht = $res[$i]["bericht"];$bericht = str_replace("<","<",$bericht);$bericht = str_replace(">",">",$bericht);echo $bericht; ------------------------------------------- DB STORAGE AFTER PUTTING line 1 line 2 line 3 -------------------------------------------- line 1<br>line 2<br>line 3 Perhaps my js replace funtion aint correct. If you need more just ask Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/#findComment-1439545 Share on other sites More sharing options...
DavidAM Posted July 5, 2013 Share Posted July 5, 2013 Why are you changing it in JS? You really should send the user input AS IS to the server; you should store it (in the database) AS ENTERED by the user. ONLY when you decide to display it in HTML should you change it using nl2br. Then you do not have to jump through these hoops. What if you decide to output the data in some other format (i.e. Plain Text email, RTF Document, etc.)? You would have to convert it from the HTML line-breaks back to newlines (or whatever is appropriate for that format). Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/#findComment-1439569 Share on other sites More sharing options...
UltraMarkus Posted July 7, 2013 Author Share Posted July 7, 2013 Okay, well the reason why I used it in JS is because my nl2br function didn't work. Normaly when I use a page refresh and send my DB data trough nl2br it catches the whole thing. Now I use this AJAX REQUEST and it fails. Tonight when I'm at home I will check what data is stored in my DB after sending it and not using the JS replace function. Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/#findComment-1439776 Share on other sites More sharing options...
UltraMarkus Posted July 11, 2013 Author Share Posted July 11, 2013 (edited) A bit later then promised. As I use a normal .val() without the replace() extended it results in the db without any sign of /n/l or <BR>. It's just a line without enters. ajax_request("berichtPlaatsen.php?table=te_koop_aangeboden&naam="+$("#naam").val()+"&email="+$("#email").val()+"&bericht="+$("#bericht").val(),"#adToevoegen",berichtGeplaatst); Edited July 11, 2013 by UltraMarkus Quote Link to comment https://forums.phpfreaks.com/topic/279719-shown-as-plain-text/#findComment-1440409 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.