D
D
Dmitry Kuzmin2015-11-11 22:05:01
PHP
Dmitry Kuzmin, 2015-11-11 22:05:01

What has changed: simplexml parsing in foreach in php 5.6?

Updated PHP to 5.6 some scripts stopped working. If this code worked before:

foreach ($xml->response->results->grouping->group as $group) 
{ 
  $results[] = Array('domain' => trim($group->doc->domain), 'url' => trim($group->doc->url),'title' => $group->doc->title);
  if ($results[$i]['domain'] == $our_domain) { $found = true; $found_index = $i; }
  $i++;
}

Here is the XML itself: xml
Now it gives an error: Invalid argument supplied for foreach()
I look at the output of the result, nothing seems to have changed.
What's my mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kuzmin, 2015-11-12
@Dimkaa

I don't know what was the problem.
Configured via xpatch
$xml = @simplexml_load_string($fp,'SimpleXMLElement', LIBXML_NOCDATA) or die("Error: Cannot create object");
foreach ($xml->xpath('//domain') as $title) {
echo "". $title. "";
}

K
krypt3r, 2015-11-12
@krypt3r

Looked. On 5.6.15, no errors were found in the console during the loop, the $results array is formed. Are you sure that this particular piece of code is problematic?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question