Solved

explode function

Posted on 2004-03-24
8
470 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 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