Jump to content

Convert New Line Characters To \n


JustinK101

Recommended Posts

How do I convert acutal line breaks into \n. I have a function which displays a javascript alert if a mysql query fails. The alert displays the full mysql query, that problem is that some of my queries are structured with line breaks such as:

 

SELECT first_name
           last_name
  FROM customers
WHERE  company_name = 'ABC'

 

These line breaks, cause the javascript alert code to fail, since javascript cannot deal with acutal new lines. Thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/57181-convert-new-line-characters-to-n/
Share on other sites

Thorpe,

 

There inst any \n displayed, they are acutal new line characters, the hidden guys. For example I pass in a string like:

 

$sql = "SELECT first_name, last_name

            FROM customers

          WHERE first_name = 'bob'";

 

See what I mean, there are newlines in that string, and I echo that string into a javascript alert() if there is an error.

Thorpe,

 

Ok so it almost worked, I changed the code to:

 

str_replace("\n", '', $sql)

 

Below (attached) is a screen shot of the alert window. You'll notice there is still some weird stuff going on, I think the whitespace might be tabs perhaps?

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.