SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML parser problem

    Hi Guys,

    I have the following XML parser and am trying to integrate BuyDomains.com into a website. It seems to work except, when trying to merge the arrays (line 15 below). The array_merge spits out the following error.

    Code:
    Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /var/www/vhosts/website.com/httpdocs/test/classes/buydomains.class.php on line 66
    The XML output can be found here: http://search.buydomains.com/broker?...25&version=1.2

    Anyones know how to fix this problem?

    PHP Code:
    function domainSearchParser($xmlText) {
                if (!
    $this->xmlParser xml_parser_create()) { 
                    return 
    false;
                }
                
    $this->xmlText $xmlText;
                
    xml_set_object($this->xmlParser,$this);
                
    xml_set_element_handler($this->xmlParser'startElement','endElement');
                
    xml_set_character_data_handler($this->xmlParser'characterHandler');
                
    xml_parser_set_option($this->xmlParserXML_OPTION_CASE_FOLDING0);
            }

            function 
    startElement($parser,$name,$attrs) {
                switch (
    strtolower($name)) {
                    case (
    'premiumdomain'):
                        
    $this->listings['domains'][$this->listingNumber] = array_merge($this->listings[$this->listingNumber],$attrs);
                        
    $this->isDomain 1;
                    break;
                    
                    case (
    'response'):
                        
    $this->listings['matches'] = $attrs;
                    break;
                }
            }
            
            function 
    endElement($parser,$name) {
                switch (
    strtolower($name)) {
                        case (
    'premiumdomain'):
                            
    $this->listingNumber++;
                            
    $this->isDomain 0;
                        break;
                }
            }
            
            function 
    characterHandler($parser,$data) {
                if (
    $this->isDomain) {
                    
    $this->listings['domains'][$this->listingNumber]['domain_name'] .= $data;
                }
            }
            
            function 
    parse() {
                
    xml_parse($this->xmlParser,$this->xmlText,true);
                return 
    $this->listings;
            } 

  2. #2
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The error message says that the first argument isn't an array -- $this->listings[$this->listingNumber] isn't an array. you can make sure it's an array.

    array($this->listings[$this->listingNumber]) You should read the change log for array_merge
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    The error message says that the first argument isn't an array -- $this->listings[$this->listingNumber] isn't an array. you can make sure it's an array.

    array($this->listings[$this->listingNumber]) You should read the change log for array_merge

    Sure, I know that argument 1 is not an array, so I guess my question is why is it not an array and how can I resolve that?

  4. #4
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Changelog

    If you're still not sure why it isn't an array after reading the changelog try executing the following;

    PHP Code:
    $myarray = array('Hello' => 'World');
    var_dump($myarray['Hello']); 
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  5. #5
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, worked a treat!


Bookmarks

Posting Permissions

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