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
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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.