Solved

explode function

Posted on 2004-03-24
8
471 Views
Last Modified: 2010-05-18
Hi everyone,
I got some help on my previous question about implode and explode. I've successfully created implode function and working now, but what I need is a working version of implode..
here is my code..

<?  

$fields = array($ver, $datt, $updated, $linkk);

$fldstring = implode('|', $fields);
$filename = "somefile.txt";
$handle = fopen ($filename, "wb");
fwrite($handle, $fldstring);

 ?>

until here it is working fine... I need help on this section....


<?
$filename = "somefile.txt";
$handle = fopen ($filename, "rb");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);

$fields = explode('|',$contents);
$ver = $fields[0];
$datt = $fields[1];
$updates = $fields[2];
$link = $fields[3];
?>

I want to display the returned result. Any suggestions ?
0
Comment
Question by:cempasha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10673098
This should work...

<?
$contents = file_get_contents("somefile.txt")

$fields = explode('|',$contents);
$ver = $fields[0];
$datt = $fields[1];
$updates = $fields[2];
$link = $fields[3];
?>

venkat.
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10673108
you can just say,

list($ver, $datt, $updates, $link) = explode("|", $contents);

venkat.
0
 
LVL 5

Author Comment

by:cempasha
ID: 10673326
I've copy pasted your code as

<?
$contents = file_get_contents("somefile.txt")

$fields = explode('|',$contents);
$ver = $fields[0];
$datt = $fields[1];
$updates = $fields[2];
$link = $fields[3];
?>
but it is giving me an Parse error on
$fields = explode('|',$contents);

i seriously do not know anything but I need to get this thing run :)
Thanks for the help
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 5

Author Comment

by:cempasha
ID: 10673337
it is the ; after $contents :) just found it..
0
 
LVL 5

Author Comment

by:cempasha
ID: 10673342
new error :(


Fatal error: Call to undefined function: file_get_contents() in index.php on line 109
like 109 is
$contents = file_get_contents("somefile.txt");

:( any ideas?
0
 
LVL 5

Author Comment

by:cempasha
ID: 10673370
<?
if(!function_exists('file_get_contents') ) {

function file_get_contents($filename, $use_include_path=0) {
/* reads out the complete contents of $filename */
$handle = fopen ($filename, "r",$use_include_path);
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
return $contents;
}

}


$contents = file_get_contents("somefile.txt");

$fields = explode('|',$contents);
$ver = $fields[0];
$datt = $fields[1];
$updates = $fields[2];
$link = $fields[3];

list($ver, $datt, $updates, $link) = explode("|", $contents);
}
?>
now it doesn't give me error but it doesn't display the results :(
0
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 250 total points
ID: 10673515

The parse error was I forgot to put semicolon on line
$contents = file_get_contents("somefile.txt")

it should be
$contents = file_get_contents("somefile.txt");

did you try to print the variable values?

print_r($fields);

or

print "$ver - $datt - $updates - $link";

venkat.
0
 
LVL 5

Author Comment

by:cempasha
ID: 10673789
seems ok now, thanks a lot :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question