php - Fastest way to retrieve part from JSON in my case -
now, use strstr data external json file. i'm not sure if it's fastest way want , can't test because json_decode don't work in code.
$before = '"this":"'; $after = '","date"'; $data = strstr(substr($url, strpos($url, $before) + strlen($before)), $after, true)
and json_decode:
$address = file_get_contents('http://json.link/?something=hello'); $data = json_decode($address); echo $data->data->this;
now, when replace first code second get:
notice: trying property of non-object
all code:
$text = "a lot of text"; $text_split = array(0 => ''); $number = 0; $words = explode(' ', $text); foreach($words $word) { if(strlen($text_split[$number]) + strlen($word) + 1 > 500) { ++$number; $text_split[$number] = ''; } $text_split[$number] .= $word.' '; } foreach($text_split $texts) { $text_encode = rawurlencode($texts); $address = file_get_contents('http://json.link/?something='.$text_encode); $data = json_decode($address); echo $data->data->this; }
what should in in case? keep using strstr or replace code work json_decode (maybe because execution time faster?)? if second option, how can make json_decode work here? thanks!
... , sorry bad english.
le: if replace $address = file_get_contents('http://json.link/?something='.$text_encode);
$address = file_get_contents('http://json.link/?something=hello');
valid result "hello" text 10 times. guess because it's in foreach.
json_decode
suggested method work json data. here think trying access invalid property in json object.
$data = json_decode($address); echo $data->data->this;
i guess need $data->date
instead of $data-data
?
Comments
Post a Comment