【发布时间】:2013-12-01 05:08:33
【问题描述】:
我认为问题出在我的逻辑上,我可能会以错误的方式解决这个问题。我想要的是
- 用php打开一个xml文档
- 按标签名称获取元素
- 那么对于每个具有子节点的节点
- 将每个字母
a替换为ა每个b替换为ბ等等。
这是我的代码,但它不起作用。
xmlDoc=loadXMLDoc("temp/word/document.xml");
$nodes = xmlDoc.getElementsByTagName("w:t");
foreach ($nodes as $node) {
while( $node->hasChildNodes() ) {
$node = $node->childNodes->item(0);
}
$node->nodeValue = str_replace("a","ა",$node->nodeValue);
$node->nodeValue = str_replace("b","ბ",$node->nodeValue);
$node->nodeValue = str_replace("g","გ",$node->nodeValue);
$node->nodeValue = str_replace("d","დ",$node->nodeValue);
// More replacements for each letter in the alphabet.
}
我认为这可能是因为多个str_replace() 调用,但即使只有一个也不起作用。我是不是走错了路,还是我错过了什么?
【问题讨论】:
标签: php xml str-replace xmlnode