Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/b6bf05ab3ab4ea5f01e5 to your computer and use it in GitHub Desktop.
Save phpfiddle/b6bf05ab3ab4ea5f01e5 to your computer and use it in GitHub Desktop.
[ Posted by Valent ] класс для анализа XML - структуры
<?php
class A {
private $a, $b;
public function __construct($ob) {
$this->a = $ob->a;
$this->b = $ob->b;
}
public function __toString() {
return "a = $this->a; b = $this->b";
}
}
$xml = <<<XML
<objects>
<object>
<a>123</a>
<b>124</b>
</object>
<object>
<a>124</a>
<b>125</b>
</object>
</objects>
XML;
$xml = simplexml_load_string($xml);
foreach ($xml->object as $ob) {
$a = new A($ob);
echo "$a<br>";
}
?>
<?php
class A {
private $a, $b;
public function __construct($ob) {
$this->a = $ob->a;
$this->b = $ob->b;
}
public function __toString() {
return "a = $this->a; b = $this->b";
}
}
$xml = <<<XML
<objects>
<object>
<a>123</a>
<b>124</b>
</object>
<object>
<a>124</a>
<b>125</b>
</object>
</objects>
XML;
$xml = simplexml_load_string($xml);
foreach ($xml->object as $ob) {
$a = new A($ob);
echo "$a<br>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment