# MySQL to ARRAY not working with STR\_REPLACE!  HELP!

**URL:** <https://www.phphelp.com/t/mysql-to-array-not-working-with-str-replace-help/15756>\
**Category:** MySQL database\
**Created:** [February 1, 2012, 12:46am UTC](https://www.phphelp.com/t/mysql-to-array-not-working-with-str-replace-help/15756 "2012-02-01T00:46:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [February 1, 2012, 12:46am UTC](https://www.phphelp.com/t/mysql-to-array-not-working-with-str-replace-help/15756/1 "2012-02-01T00:46:46Z")

</div>

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!) |

---

<div class="post-metadata">

**Author:** ![grwebugy](https://www.phphelp.com/user_avatar/www.phphelp.com/grwebugy/32/1076_2.png) [@grwebugy](https://www.phphelp.com/u/grwebugy)\
**Post date:** [September 20, 2014, 3:34pm UTC](https://www.phphelp.com/t/mysql-to-array-not-working-with-str-replace-help/15756/2 "2014-09-20T15:34:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [September 21, 2014, 1:06am UTC](https://www.phphelp.com/t/mysql-to-array-not-working-with-str-replace-help/15756/3 "2014-09-21T01:06:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [September 21, 2014, 3:52pm UTC](https://www.phphelp.com/t/mysql-to-array-not-working-with-str-replace-help/15756/4 "2014-09-21T15:52:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [October 6, 2014, 7:21pm UTC](https://www.phphelp.com/t/mysql-to-array-not-working-with-str-replace-help/15756/5 "2014-10-06T19:21:19Z")

</div>

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…
