PHP and XML question

Discussion in 'PHP' started by tdd1984, Jun 5, 2008.

  1. #1
    I'm trying to get all the URL's to return from the XML file, but its not working you can view my code below. What am I doing wrong?

    <?php
    
    
    error_reporting(E_ERROR);
    
    // The web services request
    $request =  'http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=IynIbtvV34G.J8x_W3c2xMSUWHuS7YLx32FiqZ_eThniaY0H4cZlsC.rzgzOLw--&query=inurl:.edu&results=100&xargs=0&pstart=1&b=101';
    
    // Fetch it
    $response = file_get_contents($request);
    
    
    
    
    if ($response === false) {
    	die('The request failed');
    }
    
    // Create a new DOM object
    $dom = new DOMDocument();
    $dom->load($response);
    
    
    // Load the XML into the DOM
    if ($dom->loadXML($response) === false) {
        die('Parsing failed');
    }
    
    $note = $dom->getElementsByTagName("Url"); 
    
    foreach ($note as $value){
    	
    	
    	$tasks = $value->getElementsByTagName("url");
    
    
    	echo $tasks;
    }
    
    
    ?>
    PHP:
    I thought tasks would show all the URL's from the Yahoo API search?
     
    tdd1984, Jun 5, 2008 IP
  2. adrevol

    adrevol Active Member

    Messages:
    124
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    adrevol, Jun 6, 2008 IP
  3. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    hi there,

    the code above is the working one ;)

    
    <?php
    error_reporting(E_ERROR);// The web services request
    $request =  'http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=IynIbtvV34G.J8x_W3c2xMSUWHuS7YLx32FiqZ_eThniaY0H4cZlsC.rzgzOLw--&query=inurl:.edu&results=100&xargs=0&pstart=1&b=101';
    // Fetch it
    
    $response = file_get_contents($request);
    if ($response === false) {
    	die('The request failed');
    }
    
    // Create a new DOM object
    $dom = new DOMDocument();
    $dom->load($response);
    
    // Load the XML into the DOM
    if ($dom->loadXML($response) === false) {
    	die('Parsing failed');
    }
    
    $note = $dom->getElementsByTagName("Result"); 
    
    foreach ($note as $value){ 
    	$tasks = $value->getElementsByTagName("Url")->item(0)->nodeValue;  
    	echo 'URL: ' .$tasks. '<br />';
    }
    ?>
    
    PHP:
     
    mehmetm, Jun 6, 2008 IP