Jump to content

monkeypaw201

Members
  • Posts

    376
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Contact Methods

  • Skype
    id.rather.be.flying

monkeypaw201's Achievements

Regular Member

Regular Member (3/5)

2

Reputation

  1. There is a poorly designed API library that returns data either as a PHP array or XML and to keep things standardized within my application I wanted to check if the return was XML and if so, convert to an array so the library is always outputting the same format.
  2. Hello, I have a function that converts xml2array, however it doesn't retain CDATA (multi-lines become one line). I'm not quite sure what I need to change in order to make it retain the CDATA (perhaps convert it to htmlentities). Any ideas? function xml2array($contents, $get_attributes=1, $priority = 'tag') { if(!$contents) return array(); if(!function_exists('xml_parser_create')) { //print "'xml_parser_create()' function not found!"; return array(); } //Get the XML parser of PHP - PHP must have this module for the parser to work $parser = xml_parser_create(''); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, trim($contents), $xml_values); xml_parser_free($parser); if(!$xml_values) return;//Hmm... //Initializations $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; //Refference //Go through the tags. $repeated_tag_index = array();//Multiple tags with same name will be turned into an array foreach($xml_values as $data) { unset($attributes,$value);//Remove existing values, or there will be trouble //This command will extract these variables into the foreach scope // tag(string), type(string), level(int), attributes(array). extract($data);//We could use the array by itself, but this cooler. $result = array(); $attributes_data = array(); if(isset($value)) { if($priority == 'tag') $result = $value; else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode } //Set the attributes too. if(isset($attributes) and $get_attributes) { foreach($attributes as $attr => $val) { if($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' } } //See tag status and do the needed. if($type == "open") {//The starting of the tag '<tag>' $parent[$level-1] = &$current; if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; if($attributes_data) $current[$tag. '_attr'] = $attributes_data; $repeated_tag_index[$tag.'_'.$level] = 1; $current = &$current[$tag]; } else { //There was another element with the same tag name if(isset($current[$tag][0])) {//If there is a 0th element it is already an array $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; $repeated_tag_index[$tag.'_'.$level]++; } else {//This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag.'_'.$level] = 2; if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } } $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; $current = &$current[$tag][$last_item_index]; } } elseif($type == "complete") { //Tags that ends in 1 line '<tag />' //See if the key is already taken. if(!isset($current[$tag])) { //New Key $current[$tag] = $result; $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; } else { //If taken, put all things inside a list(array) if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... // ...push the new element into that array. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; if($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } $repeated_tag_index[$tag.'_'.$level]++; } else { //If it is not an array... $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $get_attributes) { if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } if($attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } } $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken } } } elseif($type == 'close') { //End of tag '</tag>' $current = &$parent[$level-1]; } } return($xml_array); }
  3. Good catch! So we may need to do some nested queries to get this to work properly. Let me mull on it over lunch and I'll get back to you with some ideas.
  4. It does, it's only airport weather
  5. Right off the bat, I see window.location.href = "/MainPageindexSearch.php?ItemValue=" + $("#searchvalue").val(); and window.location.href = "/MainPageindexSearch.php?Value=" + $("#Newsearchvalue").val(); Shouldn't these be the same? Otherwise you're looking for a value that doesn't exist?
  6. I don't think you can do that with a function... Try either including an html page with the function or echo/printing it.
  7. You can't run client-side code with PHP. Your best bet is to use jquery's ajax() function to query a php page and then compare it to the stored/cached value of when the page was loaded.
  8. A csv file is simply a comma-delimited file with each entry being on its own line It's format is: column1,column2,column3,column4 column1,column2,column3,column4 If you have more complex strings, put quotes around some or all of the columns: colum1,"a complete sentence",order_number,something colum1,"a complete sentence",order_number,something
  9. If self-hosted software is an option, check out Open Web Analytics and Piwik.
  10. Hi aNubies, I don't believe this is possible in PHP, only in Javascript. Check out this similar thread: http://forums.phpfreaks.com/topic/66876-how-to-find-full-path-of-a-file-upload-field-in-a-form-filesfile1/
  11. I don't know if I see where the problem lies. The email address is retrieved from the database and then written into a variable. That variable is then used in the mail() function (or something equivalent). If the user cannot modify that variable they can't send it to multiple emails correct? If they try to append multiple numbers in the URL the database won't return a match (eg. it will match "123" but not "123,456"). So as long as the number going in is clean (mysql escape?) it should be fine. Did I miss something?
  12. Hopefully I don't spark a great debate about this, but could you not do it programmatically instead? eg. SELECT `item` FROM `items` then do a foreach() SELECT COUNT(`item`) AS `item_count` FROM `members` WHERE `item` = '$current_item_id_from_loop'
  13. @nitrus, I don't intend to advertise or self-promote here, but I have a collection of APIs published with Mashape including a weather API that might help you out. https://www.mashape.com/laiello/weather-4 Hope it helps. If you need some kind of data not readily available there, PM me and I'll see what I can do.
  14. Hi jkkenzie, Looking at the source code, there appear to be some hidden input fields that are being sent. Primarily a "__VIEWSTATE", which I would assume is some sort of session/temporary key to try to prevent what you are trying to do. However, never fear! There is a solution Here is some revised code. I've tested it and instead of giving me a login box it gives me an internal server error. Try it with actual credentials and let us know what happens. <?php //initiate curl process $ch = curl_init(); $url = "http://track.futuresystems.co.ke/"; //set options /* There are a number of options, which you can use to manipulate the behaviour of this ''invisible browser''. See php.net/curl for more details. */ curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/My Test Browser"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); //run the process and fetch the document $doc = curl_exec($ch); // extract viewstate input field $viewstate = explode('<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="',$doc); $viewstate = explode('" />',$viewstate[1]); $viewstate = $viewstate[0]; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/My Test Browser"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'txtUserName3=******&txtPassword3=*****&__VIEWSTATE='.$viewstate); //run the process and fetch the document $doc = curl_exec($ch); //terminate curl process curl_close($ch); //print output echo $doc; ?>
×
×
  • 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.