从XML节点中提取图像url并将其放置在新节点中


extracting image urls in an xml node and placing them in a new node

我正在从一个旧博客迁移一堆内容,我需要它是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>

我找到了一个php函数,用于将这些变量存储在数组中,但我的php还不够好,无法弄清楚如何在适当的位置创建XML节点:

$matches = array();
preg_match_all('!http://[^?#]+'.(?:jpe?g|png|gif)!Ui' , $string , $matches);

JQuery也可以。

Regex:

'<entry_text'>(?<url>.*?/&gt;)(?<text>.*?)'</entry_text'>

替换:

<entry_text>${text}</entry_text><entry_image>${url}</entry_image>
结果:

<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>