Jump to content

I had the problem with in my php code(in switch case)


sasi

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.