I have a long multiline string (its in a file that I can load into a string), lets take this as example:
<response status="success" code="19">
<result total-count="1" count="1">
<deviceconfig>
<system>
<type>
<static/>
</type>
</system>
<setting>
</deviceconfig>
</result>
</response>
<response status="success" code="19">
<result total-count="1" count="1">
<network>
<interface>
<ethernet/>
</interface>
<profiles>
<monitor-profile>
<entry name="default">
<interval>3</interval>
<action>wait-recover</action>
</entry>
</monitor-profile>
</profiles>
</network>
</result>
</response>
I need to extract the system subset of this and have it in a string with the following content taken from above example:
<system>
<type>
<static/>
</type>
</system>
In my use case both the original sample is much much larger as well as the text inside the system is a little bit larger
ok, i found a solution to do this:
preg_match_all('/(<system>.*<\/system>)/ms', file_get_contents('./myinputfile'), $xmlinit);
$output=$xmlinit[0][0]
file_put_contents('./myoutputfile', $output );
Recommendations for improvements are welcome!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments