简体   繁体   中英

Remove attributes from xml string

<soap-env:envelope xmlns:soap-enc="" xmlns:soap-env="">
    <soap-env:header>
    </soap-env:header>
    <soap-env:body>
        <ns1:createuserresponse>
            <username>weqew_825</username>
            <password>uwnoqedcjs</password>
            <result>
                <succeeded>true</succeeded>
                <errorcode>0</errorcode>
                <errortext></errortext>
            </result>
        </ns1:createuserresponse>
    </soap-env:body>
</soap-env:envelope>

I want to remove xmlns:soap-enc="" xmlns:soap-env="" from above string

you can use preg_replace

$string = preg_replace('/xmlns:.*\"/','',$string);

BUT it would be better to avoid that since again parsing that xml with SimpleXML will generate a lot of warnings (which could be surpressed with @).

a more solid solution

hope it helped

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM