I have a problem to extract a string from another string.
I would like to extract this string :
<?xml version="1.0"?> <!-- Tests completed in 1036 milliseconds. 6
tests of 6 passed, 0 failed.
--> <testsuite name=" Tests" timestamp="2012-11-19T16:37:10Z" tests="6" failures="0" time="1.036"> <testcase name="dede"
classname="test1"> </testcase> </testsuite>
From this string :
2012/11/19 17:37:09.689 - INFO. - début du test 1
2012/11/19 17:37:09.689 - INFO. - début du test 2
2012/11/19 17:38:09.689 - INFO. - début du test 3
2012/11/19 17:39:09.689 - INFO. - début du fr 4
2012/11/19 17:40:09.689 - INFO. - début du de 5
2012/11/19 17:40:48.689 - INFO. - début du de 6
2012/11/19 17:40:49.689 - INFO. - génération du résultat
<?xml version="1.0"?>
<!--
Tests completed in 1036 milliseconds.
6 tests of 6 passed, 0 failed.
-->
<testsuite name=" Tests" timestamp="2012-11-19T16:37:10Z" tests="6" failures="0" time="1.036">
<testcase name="dede" classname="test1">
</testcase>
</testsuite>
You’re probably better off not dumping the test info at the top and either including them in the XML markup, or not showing them at all.
However saying that you could probably use
strposto work out where to start extracting your string from.Then use the start position with
substr():This isn’t tested but should be roughly what you need.
strpos(): http://php.net/manual/en/function.strpos.php
substr(): http://php.net/manual/en/function.substr.php