小编and*_*wpo的帖子

在PHP中合并XML文件

我有2个文件1.xml,2.xml两个都有相似的结构,我想有一个.我尝试了很多解决方案,但我只有错误 - 坦率地说,我不知道这些脚本是如何工作的.

1.xml:

<res>
    <items total="180">
        <item>
            <id>1</id>
            <title>Title 1</title>
            <author>Author 1</author>
        </item>
        ...
    </items>
</res> 
Run Code Online (Sandbox Code Playgroud)

2.xml:

<res>
    <items total="123">
        <item>
            <id>190</id>
            <title>Title 190</title>
            <author>Author 190</author>
        </item>
        ...
    </items>
</res> 
Run Code Online (Sandbox Code Playgroud)

我想创建一个merged.xml具有以下结构的新文件

<res>
    <items total="303">
        <item>
            <id>1</id>
            <title>Title 1</title>
            <author>Author 1</author>
        </item>
        ...  //items from 1.xml
        <item>
            <id>190</id>
            <title>Title 190</title>
            <author>Author 190</author>
        </item>
        ... //items from 2.xml
    </items>
</res> 
Run Code Online (Sandbox Code Playgroud)

我该怎么办?你能解释一下这样做的方法吗?如何使用更多文件?谢谢

编辑

我尝试了什么?

<?php
function mergeXML(&$base, $add)
{
    if ( $add->count() != 0 …
Run Code Online (Sandbox Code Playgroud)

php xml merge

19
推荐指数
1
解决办法
2万
查看次数

Mod 重写传递参数规则

htaccess 文件重定向如下:

pagename.com/foo -> pagename.com/index.php?view=foo

它在 htaccess 中的工作代码是

RewriteRule ^foo$ index.php?view=foo [L]
Run Code Online (Sandbox Code Playgroud)

但我也想使用参数。所以看起来是这样的

pagename.com/foo?parameter1=bar -> pagename.com/index.php?view=foo¶meter1=bar

我已经创建的是:

RewriteRule ^foo\?([^-]+)$ index.php?view=foo&$1 [L]
Run Code Online (Sandbox Code Playgroud)

但它无法正常工作 - 我被重定向到查看 foo 但参数未传递

有任何想法吗?先感谢您

编辑:

RewriteRule ^foo/?([^-]+)$ index.php?view=foo&$1 [L,QSA] 

RewriteRule ^foo/?$ index.php?view=foo [L,QSA]
Run Code Online (Sandbox Code Playgroud)

既可以单独使用,也可以与

RewriteCond %{REQUEST_FILENAME} !-f
Run Code Online (Sandbox Code Playgroud)

无法得到它

编辑2:

对同一 foo 页面进行了另一个重写规则 - 只是将 QSA 添加到第一个页面,如下所示:

RewriteRule ^foo$ index.php?view=foo [L,QSA]
Run Code Online (Sandbox Code Playgroud)

它有效

regex .htaccess mod-rewrite

2
推荐指数
1
解决办法
5370
查看次数

标签 统计

.htaccess ×1

merge ×1

mod-rewrite ×1

php ×1

regex ×1

xml ×1