Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

explode function

Posted on 2004-03-24
8
Medium Priority
?
477 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
Technology Partners: 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!

 
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 1000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

783 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