所以我有这样的 php 函数,我想翻译成 C++:
protected function htmlTag($content, $tag, $attrName, $attrValue, $valueName)
{
preg_match_all("#<{$tag}[^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*$valueName=['\"](.+?)['\"][^>]*/?>#i", $content, $matches1);
preg_match_all("#<{$tag}[^>]*$valueName=['\"](.+?)['\"][^>]*$attrName=['\"].*?$attrValue.*?['\"][^>]*/?>#i", $content, $matches2);
$result = array_merge($matches1[1], $matches2[1]);
return empty($result)?false:$result[0];
}
使用示例:
$location = $this->htmlTag($content, 'meta', 'http-equiv', 'X-XRDS-Location', 'content');
$server = $this->htmlTag($content, 'link', 'rel', 'openid.server', 'href');
$delegate = $this->htmlTag($content, 'link', 'rel', 'openid.delegate', 'href');
(内容是 的结果$content= curl_exec($curl);
)
preg_match_all
- 搜索主题中与模式中给出的正则表达式的所有匹配项,并按照标志指定的顺序将它们放入匹配项中。找到第一个匹配后,从最后一个匹配的末尾继续进行后续搜索。
如何使用 boost::regexp 翻译它?