在 Globiflow 的 XML 文档中查找标签的第 n 个实例

Find the nth instance of a tag in XML document from Globiflow

我无法在 Globiflow(用于 Podio)中使用 preg_match_all(),因为他们坚持使用 preg_match_gf(),它具有与常规 preg_match( 类似的功能).我有以下代码:

preg_match_gf("/<zestimate><amount currency=\"USD\">(.*?)
<\/amount>/ism",*search_result_below*, 1)

我让它在以下信息中搜索一些随机的 属性(我已经大大简化了):

<comparables>
 <comp score="5.0">
  <zpid>########</zpid>
   <zestimate>
    <amount currency="USD">832447</amount>
   </zestimate>
  </comp>
 <comp score="11.0">
  <zpid>########</zpid>
   <zestimate>
    <amount currency="USD">526855</amount>
   </zestimate>
  </comp>
 <comp score="2.0">
  <zpid>########</zpid>
   <zestimate>
    <amount currency="USD">709637</amount>
   </zestimate>
  </comp>
 <comp score="6.0">
  <zpid>########</zpid>
   <zestimate>
    <amount currency="USD">607666</amount>
   </zestimate>
  </comp>
 <comp score="8.0">
  <zpid>########</zpid>
   <zestimate>
    <amount currency="USD">631700</amount>
   </zestimate>
  </comp>
</comparables>

我希望能够 select 每个 属性 <amount currency="USD"> 的每个实例,因为它们将通过自己的计算来填充自己的字段。 <comp score="#.0"> 随每个查询而变化,行位置也是如此。我无法使用 printecho,因为 Globiflow 认为它们是非法运算符。

Globiflow 为 regex and parsing text from Podio, which you may have seen. There are also some useful tools linked there for building / testing regular expressions that could be helpful. Another tool can be found here 提供了一些支持文档。

关于 Globiflow 中 preg_match_all 缺乏支持或潜在替代方案,您可以尝试联系他们的 tech support directly。虽然构建正则表达式的帮助对他们来说是 out-of-scope,但他们应该能够告诉您是否有支持的方法来全局匹配正则表达式。

我想在这里为你添加一些反馈,Josh。

在使用 PHP 计算时,与 Globiflow 配合使用的函数数量有限。 Globiflow 有自己的帮助手册,其中包含一些非常有用的链接,可以帮助您解决计算问题。

"Using PHP Calculations" 为您提供了创建计算时可以使用的所有 PHP 函数的列表, "PHP Calculation & Regex Examples" 显示了其他 Globiflow 成员使用的一些 "real life" 示例,并且 "Parsing Text in Podio with Globiflow" 带您进一步了解您所寻求的信息,并完整解释了您如何 return 在preg_match_gf 函数。

作为参考,这里是文档的链接

globiflow.com/help/

globiflow.com/help/using-php-calculations.php

globiflow.com/help/php-calculation-examples.php

globiflow.com/blog/parsing-text-in-podio-with-globiflow.php

您也可以使用preg_match_all_gf来获取每个金额,例如:

preg_match_all_gf('/<amount currency="USD">(.*?)<\/amount>/ism', [xml-token],1)
preg_match_all_gf('/<amount currency="USD">(.*?)<\/amount>/ism', [xml-token],2)
preg_match_all_gf('/<amount currency="USD">(.*?)<\/amount>/ism', [xml-token],3)

等等