Reputation: 14142
I have the following info in a db column - how could I look for the newline so I can seperate this into an array?
Address1
Address2
Address3
Upvotes: 0
Views: 98
Reputation: 91942
This is not a direct answer to your question, but a warning about using non-normalised data.
This is, in most cases, a horrible way to store data. You should store only one data entity per field. Consider adding another table called "addresses" where you can store multiple addresses for each row in the original table.
If you go ahead with your current solution you may see multiple problems along the way, such as: hard to search for entities with a certain address, concurrency problems if the addresses are updated from two clients at the same time and similar, impossible to store en address containing newlines and so on.
Upvotes: 0
Reputation: 1894
yes you can use
$arr = explode("\n",$string);
you get
$add1 = $arr[0];
$add2 = $arr[1];
$add3 = $arr[2];
Upvotes: 0
Reputation: 119
you can try with: "explode()"
$arr = explode ("\n" , $the_db_column_field)
and then into $arr you'll have te single "address1","address2","address3" etc..
(via php official)
Upvotes: 2