Answer the question
In order to leave comments, you need to log in
preg_match_all skips values, why?
Hello everyone, I wrote a lightweight parser that rips out ip adress and domain from the xml file, which are taken in tags,
$homepage = file_get_contents('url');
preg_match_all("/(\-|((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?))(?=<\/ip>)|([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}(?=<\/dns>)/", $homepage, $output_array);
foreach ($output_array1[0] as $key => $value) {
if (($key) % 2 == 0) {
echo 'add address='. $value .' ';
}
elseif (($key + 1) % 2 == 0){
echo 'name='. $value .'</br>';
}
}
Answer the question
In order to leave comments, you need to log in
The comments suggested that XML is already the solution to the problem. No need to go around, just take and extract from it those elements that are enclosed in tags
$xml = simplexml_load_file('url');
foreach ($xml->resource as $resource) {
echo "add address=" . $resource->ip . " name=" . $resource->dns . "</br>";
}
... which rips out ip adress and domain from the xml file, which are taken into tags
<?php
$array = [
0 => 'Hello',
1 => 'Word',
];
$string = var_export($array, true);
preg_match_all('/\d+\s=>\s\'(.*?)\'/ismu', $string, $matches);
$hello = $matches[1][0];
$word = $matches[1][1];
var_dump($hello, $word);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question