S
S
sochi-russia2015-12-12 08:42:31
PHP
sochi-russia, 2015-12-12 08:42:31

How to parse png?

There is such xml parsing

<?php
$url = 'http://site.ru/sitemap.xml';


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'app');

$query = curl_exec($ch);
curl_close($ch);
$xml=simplexml_load_string($query);
//$xml = str_replace('&euro;', '€', $xml);
?>

<table width=100%>

    <tr bgcolor="#CAE8F0" align="left">
        <td><b><?= $xml->offer[1]['title']?></b></td>
       <td width=5%><b><a href="<?=$xml->offer[1]["href"]?>">buy</a></td>
    </tr>

</table>

It works all right.
But the site whose xml I take has an image in each material, in the xml file there is the value "IATA". So "IATA" is exactly site.ru/imag1.png
That is, if the value in the XML file is code="IATA", then the picture will have the same value site.ru/IATA.png .
I need to take the picture using the get method knowing the path of their location and code and display it in the table. How to do it? Thanks in advance, best regards.
If possible, do not worry about withdrawing this is an even better option

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NibiruanChild, 2015-12-12
@NibiruanChild

Maybe I didn’t quite understand the task, but if there is only one picture, it is always in PNG, then why not run $xml through preg_match using the regular expression /site\.ru\/[a-zA-Z0-9]+.png/

if (preg_match("/site\.ru\/[a-zA-Z0-9]+.png/", $xml, $matches) {
    $image = $matches[0];
} else {
    echo "Изображение по шаблону не найдено";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question