function xmlStringToArray($xmlString)
{
$xmlString = preg_replace('//s','',$xmlString);
$exitAfterManyLoops = 0;
$xmlArray = array();
$currentNode = &$xmlArray;
$currentHierarchy = array();
$currentDepth = 0;
while($xmlString != '')
{
$exitAfterManyLoops++;
if($exitAfterManyLoops > 300)
{
print "BREAK";
break;
}
$xmlString = trim(substr($xmlString, strpos($xmlString, '<')));
$thisNodeAscends = (substr($xmlString, 1, 1) == '//m.sbmmt.com/m/');
$thisNodeDescends = (substr($xmlString, strpos($xmlString, '>') - 1, 1) != '//m.sbmmt.com/m/');
$nodeName = substr($xmlString, 1, strpos($xmlString, ' ') -1);
$openElement = substr($xmlString, strpos($xmlString, ' ') + 1);
$openElement = substr($openElement, 0, strpos($openElement, '>') );
if(substr($openElement, strlen($openElement) - 1, 1) == "//m.sbmmt.com/m/")
{
$openElement = substr($openElement, 0, strlen($openElement) - 1);
}
if($thisNodeAscends)
{
$currentDepth--;
$currentNode = &$currentHierarchy[$currentDepth];
}
else
{
if($thisNodeDescends)
{
$currentNode[] = array('__attributes' => parseXmlAttributesString($openElement), '__children' => array(), '__nodeName' => $nodeName);
$currentHierarchy[$currentDepth] = &$currentNode;
$currentDepth++;
$lastItem = &$currentNode[count($currentNode) - 1];
$currentNode = &$lastItem['__children'];
}
else //this node is at the same level
{
$currentNode[] = array('__attributes' => parseXmlAttributesString($openElement), '__nodeName' => $nodeName);
}
}
$xmlString = substr($xmlString, strpos($xmlString, '>') + 1);
}
return $xmlArray;
}
function parseXmlAttributesString($xmlElementString)
{
$exitAfter100Loops = 0;
$xmlElementArray = array();
while($xmlElementString != '')
{
$exitAfter100Loops++;
if($exitAfter100Loops > 100)
{
print "BREAK";
break;
}
$equalsCharacterPos = strpos($xmlElementString, '=');
$key = trim(substr($xmlElementString, 0, $equalsCharacterPos));
$xmlElementString = substr($xmlElementString, $equalsCharacterPos + 1);
$openBracket = substr($xmlElementString, 0, 1);
$xmlElementString = substr($xmlElementString, 1);
$endBracketPos = strpos($xmlElementString, $openBracket);
$value = substr($xmlElementString, 0, $endBracketPos);
$xmlElementString = substr($xmlElementString, $endBracketPos + 1);
if($key)
{
$xmlElementArray[$key]=$value;
}
}
return $xmlElementArray;
}
?>
所有计算机语言的学习都要从基础开始,《PHP入门视频教程之一周学会PHP》不仅是PHP的基础部分更主要的是PHP语言的核心技术,是学习PHP必须掌握的内容,任何PHP项目的实现都离不开这部分的内容,通过一周的深入学习让你快速掌握PHP的各项技能,助你的工作和学习更上层楼!
PHP教程246961次播放
《弹指间学会HTML视频教程》从最基本的概念开始讲起,步步深入,带领大家学习HTML,了解各种常用标签的意义以及基本用法,学习HTML知识为以后的学习打下基础
HTML教程70974次播放
CSS即层叠样式表(Cascading StyleSheet)。 在网页制作时采用层叠样式表技术,可以有效地对页面的布局、字体、颜色、背景和其它效果实现更加精确的控制。
CSS教程44087次播放
《CSS3 最新视频教程》中 CSS 用于控制网页的样式和布局。 CSS3 是最新的 CSS 标准, 本教程向您讲解 CSS3 中的新特性。通过实例进行讲解,更容易提高学习的效率!
CSS3教程30886次播放