【发布时间】:2018-02-13 22:36:36
【问题描述】:
我有 simplexml 元素对象,它是 foreach 结果的呈现输出。我必须从输出中提取值。
到目前为止,我尝试循环 simplexmlelement 对象。我正在从给定的输出中形成svg 元素。这些输出来自另一个 foreach 循环结果。
[g] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 0.2922376764472574
)
[text] => SimpleXMLElement Object
(
[@attributes] => Array
(
[fill] => #000000
[stroke] => none
[stroke-width] => 0
[stroke-linecap] => round
[stroke-linejoin] => round
[x] => 65
[y] => 85
[text-anchor] => middle
[font-size] => 90.75
[font-family] => Twine
[data-textcurve] => 0
[data-itemzoom] => 1 1
)
[tspan] => Tetst
)
)
for ($i = 0; $i < count($result); $i++)
{
//var_dump( $result[$i] );
//$op .= '<g id="0.8354780427180231">';
print_r($result[$i]);
echo "testsdf";print_r($result[$i]->g['text']);
echo 'test<g id="'.$result[$i]->g['id'].'"><text fill="'.$result[$i]->text->attributes()->fill.'" stroke="none" stroke-width="0" stroke-linecap="round" stroke-linejoin="round" x="65" y="85" text-anchor="middle" font-size="90.75" font-family="Twine" data-textcurve="0" data-itemzoom="1 1">'.$result[$i]->text['tspan'].'</text>';
echo "</g>";
echo $result[$i]->g->text['font-family'];
}
【问题讨论】:
-
只需添加尝试上述代码时发生的情况。你有什么错误吗?你没有得到你想要的元素,但它运行了?
-
如果您共享原始 XML 而不是 SimpleXMLElement 对象的转储会更容易。