It is currently Sat May 25, 2013 2:32 pm

All times are UTC


You can access below Applications



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to read text file and convert as json encode using php
PostPosted: Thu Mar 15, 2012 5:27 am 
Offline

Joined: Tue Mar 02, 2010 11:25 am
Posts: 190
Location: Kovilpatti
i want to read text file data and convert those as json encode data

Text file having data like the following

English:
grammer=http://grammersiteurl
Tamil:
tamil =http://tamilsiteurl

Code:


 $filename
="textfil.txt";//location 
   // read data from text file 
    
$lines=file($filename);
    
    foreach(
$lines as $line_num => $line)
    {
      
$findpos=strpos($line,"=");//find the equalsign position
      
$getlength=strlen($line);//get the length of the line
      
$newpos=$findpos+1;//add one to equal sign position to get next character
      
$results=substr($line,$newpos,$getlength);//get the data after equal sign 
     
$keys=substr($line,0,$findpos); //get data before equal sign
     
$value=explode("\r\n"$results); //remove if there is any line break
     
$asso[$keys]=$value[0];//store the key values
    
}
    echo 
$datajson_encode$asso,JSON_FORCE_OBJECT);

 


now i can get data as {grammer:http://grammersiteurl,tamil:http://tamilsiteurl}
Share |


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron