如何计算使用PHP在另一个数组元素中重复数组值的次数?

时间:2015-03-23 17:35:07

标签: php xml

我有一段XML数据如下:

<scientist>
  <name>Emmy Noether&amp;Amalie</name>
</scientist>

<day>
  <date>03-23-2015</date>
  <wiki>Emmy Noether&amp;Amalie was an influential German mathematician known for her groundbreaking contributions to abstract algebra and theoretical physics. Emmy Noether&amp;Amalie was born on 23 March 1882, the first of four children. In 1932 Emmy Noether and Emil Artin received the Ackermann–Teubner Memorial Award for their contributions to mathematics.</wiki>
</day>

我的问题是如何计算name的{​​{1}}值(即scientist)在上述XML元素的Emmy Noether&amp;Amalie元素中重复的次数?谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

您使用SimpleXML来解析XML吗?

如果您隔离了所有wiki标记,则可以使用substr_count函数计算名称标记出现次数