I have a list of products codes that i wish to read into an array using php.
the list is to be fetched from a website and has over 700 items looks something like this:
4310ABC
4590DEF
8950GHK
What i want to do is put every code into a php array like so:
php_array ( [0] => 4310ABC
[1] => 4590DEF
[2] => 8950GHK)
This is what i have:
$php_array = file_get_contents('http://anysite.net/product_codes.php');
print_r (explode("
",$php_array));
But my result is :
Array ( [0] => 4310ABC
4590DEF
8950GHK)
I have tried explode, preg_split('/[ ]+/', $php_array); but nothing seems to do the trick. Can anyone give me some pointers? thanks!
The lines are separated by a br, so use this instead:
$php_array = file_get_contents('http://anysite.net/product_codes.php');
print_r (explode("<br>",$php_array));
Don't forget to change the br to however it's spelled within the document you are fetching, for example it's often spelled like this:
<br />
Which is the most correct way to write it.
It would depend how your php file is echoing out the three values, so I am not sure how it is interpreting line breaks. Try echoing out the values with no line breaks, but separated by some other character like '*' or something, and then explode them along that and see if that works.