Creating PHP strings using other variables...works manually, can't figure out how automatically
Posted
by
Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2010-12-31T04:13:45Z
Indexed on
2010/12/31
4:54 UTC
Read the original article
Hit count: 214
Hello,
I'm trying to get a variable to be formed automatically using data pulled from a mysql database. I know the data is being pulled from the database in some form resembling its original form, but that data does not act the same as data that is manually typed and assigned to a string.
For example, if a cell in a mysql table says...
I said "goodbye" before I left.
She also said "goodbye."
...and I manually copy/paste it and add the necessary escapes...
$string1 =
"
I said \"goodbye\" before I left.
She also said \"goodbye.\"
";
...that does not equal...
$string1 = $mysqlResultArray['specificCellWithQuoteShownAbove']
Interestingly, if I echo both versions of $string1 and view the output, they appear to be exactly the same. But they do not function the same when put through various functions I've created. The functions only work if I do the manual copy/paste method--which is not what I want, obviously.
I'm not sure if it has to do with the line breaks or the escapes--or some combination of the two. But while both strings are superficially the same, they are apparently functionally different and I don't know why.
So how can I create $string1 without manually copy/pasting the contents from the mysql entry and instead querying for the data and assigning it to $string1 in such a way that it's exactly functionally equivalent as the manual copy/pasted string?
© Stack Overflow or respective owner