Greta Porretta
Greta Porretta

Reputation: 99

php get result of file_get_contents as array

i'm trying to receive a response from an url as :

$result = file_get_contents('http://example.com/api/test');

it simply returns some informations separated by | example :

info1|info2|info3

i want to get that result as an array

something like $result = array(file_get_contents('http://example.com/api/test'));

I just got involved in php stuffs excuse me for any confusing terms !

Upvotes: 1

Views: 2178

Answers (3)

Evan Carslake
Evan Carslake

Reputation: 2349

Very simple to do:

$resultArray = explode("|", $result);

Upvotes: 1

jfadich
jfadich

Reputation: 6348

You can use explode() to separate the data by pipe.

$result = explode('|',file_get_contents('http://example.com/api/test'))

Upvotes: 0

Greta Porretta
Greta Porretta

Reputation: 99

i just got it !

explode("|",$result);

Upvotes: 1

Related Questions