1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Make to script grabber 4shared from API

Discussion in 'Other Languages' started by miftah, Apr 20, 2012.

  1. miftah

    miftah Newbie

    Joined:
    Apr 8, 2012
    Messages:
    16
    Likes Received:
    0
    Occupation:
    student
    Location:
    indonesia
    hi there
    let make to scrip grabber 4shered from api
    if any wrong, please correction thanks
    PHP:
    <?php
      
    function xmltoarray($contents$get_attributes=1) {
        if(!
    $contents) return array();
        if(!
    function_exists('xml_parser_create')) {
            return array();
            }
        
    $parser xml_parser_create();
        
    xml_parser_set_option$parserXML_OPTION_CASE_FOLDING);
        
    xml_parser_set_option$parserXML_OPTION_SKIP_WHITE);
        
    xml_parse_into_struct$parser$contents$xml_values );
        
    xml_parser_free$parser );
        if(!
    $xml_values) return;
        
    $xml_array = array();
        
    $parents = array();
        
    $opened_tags = array();
        
    $arr = array();
        
    $current = &$xml_array;
        foreach(
    $xml_values as $data) {
            unset(
    $attributes,$value);
            
    extract($data);
            
    $result '';
            if(
    $get_attributes) {
                
    $result = array();
                if(isset(
    $value)) $result['value'] = $value;
                if(isset(
    $attributes)) {
                    foreach(
    $attributes as $attr => $val) {
                        if(
    $get_attributes == 1$result['attr'][$attr] = $val;
                        }
                    }
                } elseif(isset(
    $value)) {
                
    $result $value;
                }
            if(
    $type == "open") {
                
    $parent[$level-1] = &$current;
                if(!
    is_array($current) or (!in_array($tagarray_keys($current)))) {
                    
    $current[$tag] = $result;
                    
    $current = &$current[$tag];
                    } else {
                    if(isset(
    $current[$tag][0])) {
                        
    array_push($current[$tag], $result);
                        } else {
                        
    $current[$tag] = array($current[$tag],$result);
                        }
                    
    $last count($current[$tag]) - 1;
                    
    $current = &$current[$tag][$last];
                    }
                } elseif(
    $type == "complete") {
                if(!isset(
    $current[$tag])) {
                    
    $current[$tag] = $result;
                    } else {
                    if((
    is_array($current[$tag]) and $get_attributes == 0)
                    or (isset(
    $current[$tag][0]) and is_array($current[$tag][0]) and $get_attributes == 1)) {
                        
    array_push($current[$tag],$result);
                        } else {
                        
    $current[$tag] = array($current[$tag],$result);
                        }
                    }
                } elseif(
    $type == 'close') {
                
    $current = &$parent[$level-1];
                }
            }
        return(
    $xml_array);
        }
    ?>
     
     
    Last edited by a moderator: Apr 20, 2012
  2. thom.holland

    thom.holland Newbie

    Joined:
    Apr 23, 2012
    Messages:
    16
    Likes Received:
    0
    I'm confused, what exactly are you trying to achieve?