Jump to content

Selecting element/s from array


jumasol

Recommended Posts

Hi.
 
I am intended upon getting some css style in the head of my site when certain links are published in a given URL in it (namely the sitemap xml of the site).
 
So far, I have reached this point to create an array to list the URLs in the page:

  <?php
   $urls = array();  

$DomDocument = new DOMDocument();
$DomDocument->preserveWhiteSpace = false;
$DomDocument->load('http://www. sitio .com/index.php?option=com_xmap&view=xml&tmpl=component&id=1');
$DomNodeList = $DomDocument->getElementsByTagName('loc');

foreach($DomNodeList as $url) {
    $urls[] = $url->nodeValue;
}

//display it
echo "<pre>";
print_r($urls);
echo "</pre>";
  
  
  ?>

Which displays this array precisely:

Array
(
    [0] => http://www. sitio .com/enlace-a
    [1] => http://www. sitio .com/enlace-b
    [2] => http://www. sitio .com/enlace-c
    [3] => http://www. sitio .com/enlace-d
    [4] => http://www. sitio .com/enlace-e
    [5] => http://www. sitio .com/enlace-f
    [6] => http://www. sitio .com/enlace-g
    [7] => http://www. sitio .com/enlace-h
    [8] => http://www. sitio .com/enlace-i
)

The question now is how to get any of them (for instance "enlace-b") in some conditional script to insert the css file.

 

I would really appreciate some help.

 

Best regards.

Link to comment
https://forums.phpfreaks.com/topic/282654-selecting-elements-from-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.