Jump to content

total noob

Members
  • Posts

    37
  • Joined

  • Last visited

    Never

Everything posted by total noob

  1. Hello to all I need help on parsing this string <?php "1" "+447980123456","+447980123456","","2009-06-03","13:15:17","hello world","Orange","843822651" "+447980123456","+447980123456","","2009-06-03","15:17:13","helloworld","Orange","843822652" "+447980123456","+447980123456","","2009-06-03","17:13:15","hello,world","Orange","843822653" ?> I've tried to use this code but it give's me a blank result.. I want to echo each element using foreach loop but it does not give me any result. can someone help me on this? this is the code <?php $file = '"1" "+447980123456","+447980123456","","2009-06-03","13:15:17","hello world","Orange","843822651" "+447980123456","+447980123456","","2009-06-03","15:17:13","helloworld","Orange","843822652" "+447980123456","+447980123456","","2009-06-03","17:13:15","hello,world","Orange","843822653" '; $toinks = 0; $array = explode(',',$file ); foreach($array as $key => $value) { $value = preg_replace('/#1#/','',$value); $value = preg_replace('/[^+0-9]/','',$value); if ($value != '' || $value != NULL) { if (preg_match('/^\+/',$value)) { $newarray[$toinks] = $value; $toinks++; } } } $wenkz = $newarray; print_r($wenkz); ?> ive tried using <?php foreach($file as $me){ echo $me; } or foreach($file as $me=> $pols){ echo $pols[1]; } ?> still it does not show me any result. Im nearing my deadline to finish my system. But im stuck on this.. Please help me! thanks in advance
  2. Last question sir what if <?php /*$myAray is equal to the arrays above*/ $qarray2 = $myAray['GetSMSInboundResponse']['SMSInbounds']['InboundSMS']; foreach($qarray2 as $key => $mnb){ if($key == "ID" && $key == "Originator") $id = "$key = $mnb"; $originator = "$key = $mnb"; } ?> Is the code above works? Im not in the house today so i can't test my code. Later i will test it.. thanks
  3. So sorry for giving a nonsense reply.. Thanks for the info my problem is somehow fix..
  4. Based on your code sir <?php <?php /*$myAray is equal to the arrays above*/ $qarray2 = $myAray['GetSMSInboundResponse']['SMSInbounds']['InboundSMS']; foreach($qarray2 as $key => $mnb){ echo "$key = $mnb"; } ?> ?> could i echo just 1 element on my array? thanks
  5. Im accessing each array separately sir however i would like to do it only in one foreach loop thats applicable to both arrays.. Is this possible sir? thanks
  6. This is my two arrays sir.. <?php /*First array*/ Array ( [GetSMSInboundResponse] => Array ( [Transaction] => Array ( [Code] => 1 [Description] => Transaction OK ) [sMSInbounds] => Array ( [inboundSMS] => Array ( [0] => Array ( [iD] => 3135899 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-25 [Time] => 12:20:24 [body] => UCB2 test "SMS", with comma and qoutes for UCB.. ) [1] => Array ( [iD] => 3135903 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-25 [Time] => 12:20:24 [body] => UCB2 test "SMS", with comma and qoutes for UCB.. the second message... ) ) ) ) ) /*Second array*/ Array ( [GetSMSInboundResponse] => Array ( [Transaction] => Array ( [Code] => 1 [Description] => Transaction OK ) [sMSInbounds] => Array ( [inboundSMS] => Array ( [iD] => 3135765 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-25 [Time] => 12:09:08 [body] => UCB2 this is a test "sms", with commas.. Test onlt for UCB Function ) ) ) ) ?> the two arrays are a separate array.. Now below is my code for viewing the arrays <?php /*$myAray is equal to the arrays above*/ $qarray2 = $myAray['GetSMSInboundResponse']['SMSInbounds']['InboundSMS']; foreach($qarray2 as $mnb){ $q1 = $mnb['ID']; } ?> Now the code above works on my first array but im having trouble of getting the correct output for the second array.. Could you help me sir? thanks in advance
  7. Hello sir Im not very familiar with using mysql_real_escape_string can you give me an example on how can i implement it on my code? thanks
  8. This code does not work sir.. I think the error is cause by my array..
  9. Does some have any ideas? well, since you have named array keys, you must access them by their name, using integers will not work, if your array keys were the default integers, then your code would work. If i used a name i.e. echo $val['ID'] by getting the results of the array it wont echo any results... Im just curios where did it went wrong.. because $val isn't defined in your code. You Mean $keyws in your case Im so sorry that's not $val it was $keyws... Do you have any ideas why it cant view any results? all i see is a white page.. thanks
  10. Hello all I've been using implode function of php and suddenly i encounter a problem regarding it.. <?php $insertValues[] = "(default,'{$y}', '{$p}', '{$o}', '{$i}', '{$u}','AMM-40','test')"; $query_status = "INSERT INTO `mobile1_mn1`.`logs_inbound` (`log_id`, `originator`, `sender`, `date`, `time`, `message`, `company_id`, `keyword`) VALUES". implode(',',$insertValues); ?> When the information on $y,$p,$o,$i and $u does not have any single 'quotations' and commas it can save my information on database but when i have a string say for example the string is "he's good" and "Im, good" having a comma and quote it can't save my information anymore... can someone tell me why i have this problem? thanks in advance
  11. Does some have any ideas? well, since you have named array keys, you must access them by their name, using integers will not work, if your array keys were the default integers, then your code would work. If i used a name i.e. echo $val['ID'] by getting the results of the array it wont echo any results... Im just curios where did it went wrong..
  12. Thanks Drongo_III However i cant change the array anymore.. That array result was the result after parsing an XML string.. I have a hard time on getting the data on the array.. Im hoping that someone could solve this problem.. thanks guys..
  13. Wow great! thanks AyKay47! Im just wondering.. Why i cant get the correct data by using this? <?php foreach($qarray2 as $mnb => $keyws){ echo $val[0]. '<br/>' .$val[1]; } ?> this is the result.. Does some have any ideas?
  14. This is the original array.. <?php Array ( [GetSMSInboundResponse] => Array ( [Transaction] => Array ( [Code] => 1 [Description] => Transaction OK ) [sMSInbounds] => Array ( [inboundSMS] => Array ( [iD] => 3135765 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-25 [Time] => 12:09:08 [body] => UCB2 this is a test "sms", with commas.. Test onlt for UCB Function ) ) ) ) ?> I simplified the above array hoping to get an easier array by doing this. <?php $qarray2 = $myAray['GetSMSInboundResponse']['SMSInbounds']['InboundSMS']; foreach($qarray2 as $keys){ echo $keys; } ?> However if i echo the array using this <?php $qarray2 = $myAray['GetSMSInboundResponse']['SMSInbounds']['InboundSMS']; foreach($qarray2 as $keys){ echo $keys[1]; } ?> or <?php $qarray2 = $myAray['GetSMSInboundResponse']['SMSInbounds']['InboundSMS']; foreach($qarray2 as $keys){ echo $keys['Body']; } ?> I cant get any results.. I would like to echo each data on a newline but im stuck on how to do it... Can someone help me? Thanks guys.. - thanks scootstah...
  15. Hello Can someone help me with this array? <?php Array ( [inboundSMS] => Array ( [iD] => 3135765 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-25 [Time] => 12:09:08 [body] => UCB2 this is a test "sms", with commas.. Test onlt for UCB Function ) ) ?> Ive been using a foreach loop to each the array results but it wont echo any result <?php foreach($qarray2 as $mnb => $keyws){ echo $keyws[1]; } ?> I would like to echo the array results but im having a hard time on it.. can someone help me on this? Any help will be appreciated.. thanks guys.
  16. "weird results" means that i wont echo the same result as of using the second string.. Can someone help me? any help will be appreciated.. thanks
  17. Hello all I have here a code for parsing an XML string <?php function xml2array($contents, $get_attributes=1, $priority = 'tag') { if(!$contents) return array(); if(!function_exists('xml_parser_create')) { return array(); } $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; $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; $repeated_tag_index = array(); foreach($xml_values as $data) { unset($attributes,$value); extract($data); $result = array(); $attributes_data = array(); if(isset($value)) { if($priority == 'tag') $result = $value; else $result['value'] = $value; } if(isset($attributes) and $get_attributes) { foreach($attributes as $attr => $val) { if($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; } } if($type == "open") { $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 { if(isset($current[$tag][0])) { $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; $repeated_tag_index[$tag.'_'.$level]++; } else { $current[$tag] = array($current[$tag],$result); $repeated_tag_index[$tag.'_'.$level] = 2; if(isset($current[$tag.'_attr'])) { $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") { if(!isset($current[$tag])) { $current[$tag] = $result; $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; } else { if(isset($current[$tag][0]) and is_array($current[$tag])) { $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 { $current[$tag] = array($current[$tag],$result); $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $get_attributes) { if(isset($current[$tag.'_attr'])) { $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]++; } } } elseif($type == 'close') { $current = &$parent[$level-1]; } } return($xml_array); } /* $XMLS = '<?xml version="1.0" encoding="UTF-8"?><GetSMSInboundResponse><Transaction><Code>1</Code><Description>Transaction OK</Description></Transaction><SMSInbounds><InboundSMS><ID>3135765</ID><Originator>+447537404702</Originator><Destination>+447537404702</Destination><Keyword>UCB2</Keyword><Date>2012-01-25</Date><Time>12:09:08</Time><Body>UCB2 this is a test "sms", with commas.. Test onlt for UCB Function</Body></InboundSMS></SMSInbounds></GetSMSInboundResponse>'; */ $XMLS = ' <?xml version="1.0" encoding="UTF-8"?><GetSMSInboundResponse><Transaction><Code>1</Code><Description>Transaction OK</Description></Transaction><SMSInbounds><InboundSMS><ID>3135899</ID><Originator>+447537404702</Originator><Destination>+447537404702</Destination><Keyword>UCB2</Keyword><Date>2012-01-25</Date><Time>12:20:24</Time><Body>UCB2 test "SMS", with comma and qoutes for UCB..</Body></InboundSMS><InboundSMS><ID>3135903</ID><Originator>+447537404702</Originator><Destination>+447537404702</Destination><Keyword>UCB2</Keyword><Date>2012-01-25</Date><Time>12:20:24</Time><Body>UCB2 test "SMS", with comma and qoutes for UCB.. the second message...</Body></InboundSMS></SMSInbounds></GetSMSInboundResponse> '; $myAray = xml2array($XMLS, $get_attributes=1, $priority = 'tag'); $innerArray = $myAray['GetSMSInboundResponse']['SMSInbounds']['InboundSMS']; foreach ($innerArray as $item) { echo $item['ID'] . '<br/>' . $item['Originator'] . '<br/>' . $item['Destination'] . '<br/>' . $item['Keyword'] . '<br/>' . $item['Date']. '<br/>' . $item['Time']. '<br/>' . $item['Body'] . '<hr/>';//. PHP_EOL; } ?> And i have to kinds of XML First XML Result of the first XML Second XML Result for the second XML Now my problem is that when i use the second XML string it would echo the results just fine but when i use the first XML string i would echo weird results... Can someone help me with my problem? i think the problem is on how i echo the results but still i can't fix this problem.. Please help me guys.. thanks
  18. Hello sir I have a problem with this line of code.. $innerArray = $array['GetSMSInboundResponse']['SMSInbounds']['InboundSMS']; Where specifically will i put it on my function? thanks
  19. This is actually an array.. This array is the result after parsing an XML string.. Below is the function that returns the array <?php function xml2array($contents, $get_attributes=1, $priority = 'tag') { if(!$contents) return array(); if(!function_exists('xml_parser_create')) { return array(); } $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; $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; $repeated_tag_index = array(); foreach($xml_values as $data) { unset($attributes,$value); $result = array(); $attributes_data = array(); if(isset($value)) { if($priority == 'tag') $result = $value; else $result['value'] = $value; } if(isset($attributes) and $get_attributes) { foreach($attributes as $attr => $val) { if($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; } } if($type == "open") { $parent[$level-1] = &$current; if(!is_array($current) or (!in_array($tag, array_keys($current)))) { $current[$tag] = $result; if($attributes_data) $current[$tag. '_attr'] = $attributes_data; $repeated_tag_index[$tag.'_'.$level] = 1; $current = &$current[$tag]; } else { if(isset($current[$tag][0])) { $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; $repeated_tag_index[$tag.'_'.$level]++; } else { $current[$tag] = array($current[$tag],$result); $repeated_tag_index[$tag.'_'.$level] = 2; if(isset($current[$tag.'_attr'])) { $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") { if(!isset($current[$tag])) { $current[$tag] = $result; $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; } else { if(isset($current[$tag][0]) and is_array($current[$tag])) { $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 { / $current[$tag] = array($current[$tag],$result); $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $get_attributes) { if(isset($current[$tag.'_attr'])) { $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]++; } } } elseif($type == 'close') { $current = &$parent[$level-1]; } } return($xml_array); } $XMLS = ' <?xml version="1.0" encoding="UTF-8"?><GetSMSInboundResponse><Transaction><Code>1</Code><Description>Transaction OK</Description></Transaction><SMSInbounds><InboundSMS><ID>3126861</ID><Originator>+447537404702</Originator><Destination>+447537404702</Destination><Keyword>UCB2</Keyword><Date>2012-01-24</Date><Time>13:21:45</Time><Body>UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote...</Body></InboundSMS><InboundSMS><ID>3126867</ID><Originator>+447537404702</Originator><Destination>+447537404702</Destination><Keyword>UCB2</Keyword><Date>2012-01-24</Date><Time>13:21:45</Time><Body>UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote 2... </Body></InboundSMS></SMSInbounds></GetSMSInboundResponse> '; print_r(xml2array($XMLS, $get_attributes=1, $priority = 'tag')); ?> Do you have any ideas on how to extract the information that i want? thanks guys..
  20. A very help full link! http://www.bin-co.com/php/scripts/xml2array/
  21. Hello all.. I have here my array results.. does anyone knows how to simplify this array? i would like to get the following value and echo it... Array ( [GetSMSInboundResponse] => Array ( [Transaction] => Array ( [Code] => 1 [Description] => Transaction OK ) [sMSInbounds] => Array ( [inboundSMS] => Array ( [0] => Array ( [iD] => 3126861 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-24 [Time] => 13:21:45 [body] => UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote... ) [1] => Array ( [iD] => 3126867 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-24 [Time] => 13:21:45 [body] => UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote 2... ) ) ) ) ) I would like to echo the result on this part of array [0] => Array ( [iD] => 3126861 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-24 [Time] => 13:21:45 [body] => UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote... ) [1] => Array ( [iD] => 3126867 [Originator] => +447537404702 [Destination] => +447537404702 [Keyword] => UCB2 [Date] => 2012-01-24 [Time] => 13:21:45 [body] => UCB2 this is a "quotes", single quote... Test for receiving a message having commas, double quotes and single quote 2... ) but i have problems on how to do it.. please help me guys.. thanks in advance
  22. Hello Guys Does anyone knows how to parse an XML format? Im just learning how to parse a CSV string but now my job suddenly involves parsing an XML string.. Can you help me on this guys? This is my XML string.. the result is similar to this I would like to put the result on an array or a multi dimentional array.. I dont have any ideas about XML parsing i myself is having trouble of parsing a CSV string I would love to hear you comments or solution to my problem. Any help will be appreciated... thanks
  23. Hello sir I think im stuck on this part of the code foreach($parts as $value) { //rerun the function on each line. $result = parse_csv($value,$delimiter,$quote,$newline); //only include the results, if there is more than 1 line; if(isset($result[1])) { $arr[] = $result; } } When i change $result[1] into $result[2] i would get the result that i want however on that result it wont show my mobile numbers that is not equal +447537404702 Thanks in advance sir....
  24. Hello to all... Can someone help me on this one? I have a hard time on modifying this code. This code was given to me as the reply on my old post.. However i put the wrong string on that post.. Now my problem is how to parse again this string I need to drop the #1#, and split the string into an array on +447537404702..Please refer on the code below function parse_csv($line,$delimiter=',',$quote = '"',$newline="\n") { $line = str_replace("\r\n",$newline,$line); //change extended newlines. $line = str_replace("\n",$newline,$line); //this is here in case you pass a different newline to the function. $line = str_replace('"",""','',$line); //remove double quoted commas. $line = str_replace($quote,'',$line); //remove quotes. $line = preg_replace('~,{2,}~',',',$line); //remove double commas. if(strstr($line,$newline)) { $parts = explode($newline,$line); //all new lines should be an array. } if(isset($parts) && is_array($parts)) { //if a newline exists foreach($parts as $value) { //rerun the function on each line. $result = parse_csv($value,$delimiter,$quote,$newline); //only include the results, if there is more than 1 line; if(isset($result[1])) { $arr[] = $result; } } } else { $arr = explode($delimiter,$line); //make an array based on the delimiter. //cleanup = delete lines that has no values. foreach($arr as $k => $v) { if(empty($v)) { unset($arr[$k]); } } } return $arr; } $file ='#1# "3032117","+639217195804","+447537404702","test","2012-01-13","03:26:15","test another sample sms. this is a sample sms","" "3032118","+639105701066","+447537404702","test","2012-01-14","03:27:12","test sms sample 2. test only.",""'; $array = parse_csv($file,',','"',"+447980123456"); echo '<pre>' . print_r($array,true) . '</pre>'; //show the array construct. //echoing the values out. foreach($array as $key => $value) { echo '<h4>' . $key . '</h4>'; foreach($value as $v2) { echo $v2 . '<br />'; } echo '<hr />'; } This is the wrong string Can someone help me on this one? any help will be appreciated... Thanks in advance! This is the link on my old post http://www.phpfreaks.com/forums/index.php?topic=351398.new;topicseen#new
×
×
  • 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.