正则表达式 - 在 XML 标签之间移动内容 [英] Regular expression - moving content between XML tags

查看:69
本文介绍了正则表达式 - 在 XML 标签之间移动内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个在 XML 标签之间移动内容的正则表达式.这是 XML 文件的标记:http://bit.ly/1Gyd1oR

I need a regular expression that moves content between XML tags. Here is the markup of the XML file: http://bit.ly/1Gyd1oR

正如您在记录标签中看到的那样,有一个标题和内容标签.现在我想用标题标签的内容替换内容标签中的 {title}.

As you can see within a record tag there is a title and content tag. Now I want to replace {title} in the content tag with the content of the title tag.

推荐答案

尝试类似:

$pattern = '#(<record[^>]+><title>([^<]+)</title><content><!\[CDATA\[<html><head><title>)\{title\}#';
$result  = preg_replace($pattern, '$1$2', $input)

但是糟糕 - 考虑改用 XML 库.

But yuck - consider using XML libraries instead.

原始注释(编辑前):这个正则表达式最初是 Java 风格的 - 我(potame)没有在 PHP 中运行它.

这篇关于正则表达式 - 在 XML 标签之间移动内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆