Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

explode function

Posted on 2004-03-24
8
Medium Priority
?
475 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
Industry Leaders: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

715 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