Php 提取xml节点中的图像URL并将其放置在新节点中
我正在从一个旧博客迁移一堆内容,我需要它是XML格式的。问题是,我的旧站点不包含用于图像URL的单独节点,而新站点则包含,因此我需要使用如下所示的XML节点:Php 提取xml节点中的图像URL并将其放置在新节点中,php,xml,regex,migration,Php,Xml,Regex,Migration,我正在从一个旧博客迁移一堆内容,我需要它是XML格式的。问题是,我的旧站点不包含用于图像URL的单独节点,而新站点则包含,因此我需要使用如下所示的XML节点: <entry_text><img src="http://site.com/image.jpg" width="300" height="429" align="left"
<entry_text><img src="http://site.com/image.jpg" width="300" height="429" align="left" hspace="5" vspace="5" />Lorem Ipsum Dolor sit amet
</entry_text>
<entry_text>Lorem Ipsum Dolor sit amet</entry_text>
<entry_image><img src="http://site.com/image.jpg" width="300" height="429" align="left" hspace="5" vspace="5" /></entry_image>
JQuery也可以工作。Regex:
\<entry_text\>(?<url>.*?/>)(?<text>.*?)\</entry_text\>
\(?*?/)(?*?)\
替换:
<entry_text>${text}</entry_text><entry_image>${url}</entry_image>
${text}${url}
结果:
<entry_text>Lorem Ipsum Dolor sit amet</entry_text><entry_image><img src="http://site.com/image.jpg" width="300" height="429" align="left" hspace="5" vspace="5" /></entry_image>
Lorem Ipsum Dolor sit ametimg src=”http://site.com/image.jpg“width=“300”height=“429”align=“left”hspace=“5”vspace=“5”/
Tested with(仍然是我最喜欢的快速编写和测试正则表达式的工具)谢谢-我在mac上,所以无法使用该工具-但我会看看是否能找到其他工具。我想您不知道如何用javascript编写此语句来将正则表达式应用于字符串。我收到一个无效的正则表达式错误。这就是我尝试的:var entry_text=$('entry_text').text();var split=new RegExp('\(?*?/)(?*?);
<entry_text>Lorem Ipsum Dolor sit amet</entry_text><entry_image><img src="http://site.com/image.jpg" width="300" height="429" align="left" hspace="5" vspace="5" /></entry_image>