Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 提取xml节点中的图像URL并将其放置在新节点中_Php_Xml_Regex_Migration - Fatal编程技术网

Php 提取xml节点中的图像URL并将其放置在新节点中

Php 提取xml节点中的图像URL并将其放置在新节点中,php,xml,regex,migration,Php,Xml,Regex,Migration,我正在从一个旧博客迁移一堆内容,我需要它是XML格式的。问题是,我的旧站点不包含用于图像URL的单独节点,而新站点则包含,因此我需要使用如下所示的XML节点: <entry_text>&lt;img src=&quot;http://site.com/image.jpg&quot; width=&quot;300&quot; height=&quot;429&quot; align=&quot;left&quot

我正在从一个旧博客迁移一堆内容,我需要它是XML格式的。问题是,我的旧站点不包含用于图像URL的单独节点,而新站点则包含,因此我需要使用如下所示的XML节点:

<entry_text>&lt;img src=&quot;http://site.com/image.jpg&quot; width=&quot;300&quot; height=&quot;429&quot; align=&quot;left&quot; hspace=&quot;5&quot; vspace=&quot;5&quot; /&gt;Lorem Ipsum Dolor sit amet
</entry_text>
<entry_text>Lorem Ipsum Dolor sit amet</entry_text>
<entry_image>&lt;img src=&quot;http://site.com/image.jpg&quot; width=&quot;300&quot; height=&quot;429&quot; align=&quot;left&quot; hspace=&quot;5&quot; vspace=&quot;5&quot; /&gt;</entry_image>
JQuery也可以工作。

Regex:

\<entry_text\>(?<url>.*?/&gt;)(?<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>&lt;img src=&quot;http://site.com/image.jpg&quot; width=&quot;300&quot; height=&quot;429&quot; align=&quot;left&quot; hspace=&quot;5&quot; vspace=&quot;5&quot; /&gt;</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>&lt;img src=&quot;http://site.com/image.jpg&quot; width=&quot;300&quot; height=&quot;429&quot; align=&quot;left&quot; hspace=&quot;5&quot; vspace=&quot;5&quot; /&gt;</entry_image>