Using escape_str() or escape() produces a backslash \n character rather than \r\n - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Using escape_str() or escape() produces a backslash \n character rather than \r\n (/showthread.php?tid=40308) |
Using escape_str() or escape() produces a backslash \n character rather than \r\n - El Forum - 04-05-2011 [eluser]brandobandido[/eluser] Hi CI Experts, Badly need your help here. I'm stuck to this issue for a couple of weeks already. The issue was using the escape_str() or escape() produces a backslash n (\n) in the database record. E.g. if I type in the text field Code: Hi This is it Code: Hi This is it In the database, I will get Code: Hi This is it\n Hi This is it The output in my view in the textarea is this Code: Hi This is it\n Hi This is it If I use stripslashes(), it will remove the slash and the "n" will still remain. So the output will become like this Code: Hi This is it n Hi This is it What am I doing wrong here? Or is this a bug? Any help would be greatly appreciated. Thanks! Using escape_str() or escape() produces a backslash \n character rather than \r\n - El Forum - 04-05-2011 [eluser]InsiteFX[/eluser] If you use Active Record you do not have to worry about this, Active Record will escape everything automatically. Code: $sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')"; InsiteFX Using escape_str() or escape() produces a backslash \n character rather than \r\n - El Forum - 04-06-2011 [eluser]brandobandido[/eluser] [quote author="InsiteFX" date="1302032723"]If you use Active Record you do not have to worry about this, Active Record will escape everything automatically. Code: $sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')"; InsiteFX[/quote] Hi InsiteFX! First of all, thanks for your quick reply. By the way, I would just like to confirm. You mean I don't need the escape_str() and escape() when I'm using active record? Correct? Using escape_str() or escape() produces a backslash \n character rather than \r\n - El Forum - 04-06-2011 [eluser]brandobandido[/eluser] [quote author="InsiteFX" date="1302032723"]If you use Active Record you do not have to worry about this, Active Record will escape everything automatically. Code: $sql = "INSERT INTO table (title) VALUES('".$this->db->escape_str($title)."')"; InsiteFX[/quote] I tried removing the escape_str(). When I insert string with quotes, it doesn't escape them. For example, I inserted "It's My Life". I'm expecting that in the db it will become "It\'s My Life". But it's the same. What's your insight about this InsiteFX? Thanks so much man! Using escape_str() or escape() produces a backslash \n character rather than \r\n - El Forum - 04-06-2011 [eluser]InsiteFX[/eluser] Correct, Active Record handles the escaping automatically. Code: // you must use an array like this! InsiteFX |