Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    118
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Extracting from array / xml issue

    I've built a basic CMS using PHP and xml documents.

    This is the code I've used to open a folder containing news articles, It goes through each one identifying specific elements in each then echoing them as desired. The only problem is, its not echoing anything.

    I had this working fine using PHP 4 but in the upgrade to 5 somethings gone wrong. Can anyone see what?

    PHP Code:
    <?php
    $dh 
    opendir('./xmlfilms/');

    $fileCount 0;
    while (
    $file readdir($dh) and $fileCount 3){
        if (
    preg_match("/^..?$/"$file)) {
            continue;
        }
        
    $doc = new DOMDocument();
        
    $doc->load("./xmlfilms/" $file);
        
    $items $doc->getElementsByTagName("status");
        
    $status extractText($items);

        
    $items $doc->getElementsByTagName("headline");
        
    $headline extractText($items);
            
        
    $items $doc->getElementsByTagName("client");
        
    $client extractText($items);
        
        
    $items $doc->getElementsByTagName("featured");
        
    $featured extractText($items);
        
        
    $items $doc->getElementsByTagName("vimeo");
        
    $vimeo extractText($items);
        

        
    $items $doc->getElementsByTagName("keywords");
        
    $keywords extractText($items);
        
        
    $items $doc->getElementsByTagName("uploadFilename_0");
        
    $uploadFilename_0 extractText($items);


        if (
    $featured != "featured"){
            continue;
        }
        echo 
    "<td align='centre'>";
        echo 
    "<span class='featuretitle'>" $headline "</class><br><br>";
        echo 
    "<a href='http://vimeo.com/" $vimeo "' rel='prettyPhoto' title=''><img src='images/filmsimg/" $uploadFilename_0 "' style='opacity:0.8;filter:alpha(opacity=80)'
    onmouseover='this.style.opacity=1;this.filters.alpha.opacity=100' onmouseout='this.style.opacity=0.8;this.filters.alpha.opacity=80'></a></td><td valign='top'>"
    ;
        echo 
    "</td>";
        
        
    $fileCount++;
    }
    ?>
    The function "extractText" is:
    PHP Code:
                            <?php
    function extractText($array){
        foreach (
    $items as $item){
        echo 
    $item->nodeValue ."\n";

    }
    ?>
    Thanks

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    is this the function?
    PHP Code:
    function extractText($items){
        foreach (
    $items as $item){
        echo 
    $item->nodeValue ."\n";


    If not, the parameter variable is $array, but you are looping over $items.

    Plus, the function is echoing, not returning, so any assignment will be NULL:
    PHP Code:
    $status extractText($items);

    var_dump$status ); // NULL 
    Sooo... not sure why the assignments are there.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •