MySQL to ARRAY not working with STR_REPLACE! HELP!

I’m stumped on this one. I have a database with simple text data. I load the small database into a multidimensional array. The data is there, I have verified this. Next, I attempt to STRIPSLASHES or STR_REPLACE them and nothing happens. If I manually create the same ARRAY, it works correctly. ???

Here is the code sample:

[php]
while($row = mysql_fetch_array($dbResID)) {
$all[] = $row;
}
$temp = $all[0][2]; // This record contains the following…
//$temp = “TESTING: line 1 \r\n\r\n **** line 2 **** \r\n\r\n **** line 3 **** \n”; // This line works…
$DisplayLines = str_replace("\r\n", “
”, $temp);
echo ($DisplayLines);
[/php]

(Also, I displayed the entire database into a table

…etc… and the data is all in place!)

Sounds like you should be using nl2br?
http://php.net/manual/en/function.nl2br.php

I have had the same issue before and while nl2br may work, it didn’t in my case. If I remember correctly, I ended up using just ‘\n’ and the script started functioning correctly.

And why are you still using deprecated functions?

You are trying to do an action on an array without iterating through it. Move your str_replace into the while loop. If you do it outside of that you will need to put it in a foreach loop.

Wow! That was an old thread I started two years ago… Forgot all about it.

What I was trying to do is save HTML code inside the DB and use it as a kind of template for sections of
code. I had a use for it back two years ago. Since then, I just created the entire page as an HTML
and place special tags in it and just replace the tags.

A million ways to do code… But, thanks for the help…

Sponsor our Newsletter | Privacy Policy | Terms of Service