Re: String variable read from Mysql DB + echo = Newline problem



weirdstuff wrote:
Errr, what? :)

Ok I had figured that a backslash was being added when I read the
string from DB, but all my attempts of correcting that have failed.
What we have here is a case where knowing how the output is formatted
_exactly_ is very important. So it would be nice to be able to
"manually" format stuff like newlines and breaks.

Now, your suggestions:


So, what you have to do is change your formatting characters. Replace
"\\n" with "\n" and "\\r" with "\r", for instance.


The string already has single backslash in the database. If I add
another "just for fun" I just get two in the output. If I then do a
stripslashes() on one or the other then that doesn't help either.


Or, alternatively, put the actual characters themselves in the database.


Thats exactly what I'm trying not to do.
So we can agree that the problem is when I am getting the string from
the database. Then PHP (or MySQL?) does some funkyness to the string
variable which makes PHP think that \n means it should print
"backslash" and "en"

Jolly good show. Now lets fix it! :)


Please read it again. Replacing "\\n" with "\n" will not add another backslash. It will convert the backslash and en to a newline character.

You really only have two choices. Either put the characters themselves in the database, or put something representing the characters in the database and substitute after you read them out.

And BTW - you cannot exactly control formatting on the user's browser. All you can do is recommend formatting. If you want exact, create a PDF.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.



Relevant Pages

  • Re: Hot to parse RTF String
    ... Define styles in the Word document template containing the formatting ... Use VBA in Word to retrieve the strings from the database. ... automatically apply the associated style to each string as it brings it in. ... Word document, but parsed, that is formatted. ...
    (microsoft.public.word.docmanagement)
  • Re: String variable read from Mysql DB + echo = Newline problem
    ... The string already has single backslash in the database. ... Then PHP does some funkyness to the string ...
    (comp.lang.php)
  • Backslash quoting - Bug in DBI:CSV driver?
    ... I insert a string containing a backslash into my database, ... Quoted Input: 'backslash\\' ...
    (perl.dbi.users)
  • Re: Oracle and bindcolumns
    ... You probably already know this, but on the chance you don't, ... you want to put that date into a "DATE" column in the database. ... the database into a string variable. ... Only gotcha is with formatting -- you'll need to either: ...
    (perl.dbi.users)
  • Re: A little Rolodex [revised]
    ... including alpha sort and searching for any embedded string, ... In this application, a database is a directory, ... you may optionally provide any alternate UCASE program, ... NN -> first store NN as key length ...
    (comp.sys.hp48)