sasi Posted March 28, 2007 Share Posted March 28, 2007 Hello everybody, This is sasi working as a software programmer,and i am working on php from past 2 months and right now i am doing a small convertion program means(converting the string from reading a file(31 records) in to the MySql date format).so the problem is i used the switch case where the value is not checking why it is so happening.please kindly view this and respond to it immediately. here is my code: <?php //Open the file from where we have to parse the date format into the MySql date format. $file = fopen("new.txt","r+")or exit("Unable to open file!"); echo "file opened"."</br>"; //Read the entire file up to the EOF. while(!feof($file)) { $string = array();//Array to store the entire data of the file $string = fgets($file)."</br>";//Reads the entire file $word = substr($string,3,4)."</br>";//Getting the day from the array which contains the data of the file //echo "Month is:".$word; $a = trim($word); echo "new value:".$a; $word1 = substr($string,8,2)."</br>";//Getting the month from the array echo "Date is:".$word1; $word3 = substr($string,20,4)."</br>";//Getting the year from the array echo "Year is:".$word3; $word4 = substr($string,25)."</br>";//Getting the reaming data from the arrray switch($z)//Switch case to verify and print the month in the number format. { case "Jan": echo "checking:".$a; echo $word3."\t"."-".$word1."-"."01"."\t".$word4; break; case "Feb": echo date("Y")."-".$word1."-"."02"."\t".$word4; break; case "Mar": echo date("Y")."-".$word1."-"."03"."\t".$word4; break; case "Apr": echo date("Y")."-".$word1."-"."04"."\t".$word4; break; case "May": echo date("Y")."-".$word1."-"."05"."\t".$word4; break; case "Jun": echo date("Y")."-".$word1."-"."06"."\t".$word4; break; case "Jul": echo date("Y")."-".$word1."-"."07"."\t".$word4; break; case "Aug": echo date("Y")."-".$word1."-"."08"."\t".$word4; break; case "Sep": echo date("Y")."-".$word1."-"."09"."\t".$word4; break; case "Oct": echo date("Y")."-".$word1."-"."10"."\t".$word4; break; case "Nov": echo date("Y")."-".$word1."-"."11"."\t".$word4; break; case "Dec": echo date("Y")."-".$word1."-"."12"."\t".$word4; break; default: echo "final result:".$word; }*/ }//End of the while loop fclose($file);//Close the file ?> regards, sasi. Link to comment https://forums.phpfreaks.com/topic/44588-i-had-the-problem-with-in-my-php-codein-switch-case/ Share on other sites More sharing options...
kenrbnsn Posted March 28, 2007 Share Posted March 28, 2007 You're doing a "switch($z)", but I don't see $z defined anywhere. Also, please edit your post and put the tag before your code and after. It will make your code much easier to read. Ken Link to comment https://forums.phpfreaks.com/topic/44588-i-had-the-problem-with-in-my-php-codein-switch-case/#findComment-216570 Share on other sites More sharing options...
sasi Posted March 28, 2007 Author Share Posted March 28, 2007 Sorry that was the mistaken by me $z was printing mistake.I had used $a. Link to comment https://forums.phpfreaks.com/topic/44588-i-had-the-problem-with-in-my-php-codein-switch-case/#findComment-216574 Share on other sites More sharing options...
sasi Posted March 28, 2007 Author Share Posted March 28, 2007 Hello everybody, This is sasi working as a software programmer,and i am working on php from past 2 months and right now i am doing a small convertion program means(converting the string from reading a file(31 records) in to the MySql date format).so the problem is i used the switch case where the value is not checking why it is so happening.please kindly view this and respond to it immediately. here is my code: <?php //Open the file from where we have to parse the date format into the MySql date format. $file = fopen("new.txt","r+")or exit("Unable to open file!"); echo "file opened"."</br>"; //Read the entire file up to the EOF. while(!feof($file)) { $string = array();//Array to store the entire data of the file $string = fgets($file)."</br>";//Reads the entire file $word = substr($string,3,4)."</br>";//Getting the day from the array which contains the data of the file //echo "Month is:".$word; $a = trim($word); echo "new value:".$a; $word1 = substr($string,8,2)."</br>";//Getting the month from the array echo "Date is:".$word1; $word3 = substr($string,20,4)."</br>";//Getting the year from the array echo "Year is:".$word3; $word4 = substr($string,25)."</br>";//Getting the reaming data from the arrray switch($a)//Switch case to verify and print the month in the number format. { case "Jan": echo "checking:".$a; echo $word3."\t"."-".$word1."-"."01"."\t".$word4; break; case "Feb": echo date("Y")."-".$word1."-"."02"."\t".$word4; break; case "Mar": echo date("Y")."-".$word1."-"."03"."\t".$word4; break; case "Apr": echo date("Y")."-".$word1."-"."04"."\t".$word4; break; case "May": echo date("Y")."-".$word1."-"."05"."\t".$word4; break; case "Jun": echo date("Y")."-".$word1."-"."06"."\t".$word4; break; case "Jul": echo date("Y")."-".$word1."-"."07"."\t".$word4; break; case "Aug": echo date("Y")."-".$word1."-"."08"."\t".$word4; break; case "Sep": echo date("Y")."-".$word1."-"."09"."\t".$word4; break; case "Oct": echo date("Y")."-".$word1."-"."10"."\t".$word4; break; case "Nov": echo date("Y")."-".$word1."-"."11"."\t".$word4; break; case "Dec": echo date("Y")."-".$word1."-"."12"."\t".$word4; break; default: echo "final result:".$word; }*/ }//End of the while loop fclose($file);//Close the file ?> regards, sasi. Link to comment https://forums.phpfreaks.com/topic/44588-i-had-the-problem-with-in-my-php-codein-switch-case/#findComment-216575 Share on other sites More sharing options...
dsaba Posted March 28, 2007 Share Posted March 28, 2007 echo $a to check what that value is i see its trim($word), but maybe it trimmed to much also add a default statement to your switch statement default: echo "$a was not any of the cases in my switch statement"; *EDIT-- woops obviously you have done these things since you have done this, you should be able to tell on your own where the script is messing up also you might want to take this out " }*/" the "*/" Link to comment https://forums.phpfreaks.com/topic/44588-i-had-the-problem-with-in-my-php-codein-switch-case/#findComment-216600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.