Solved

explode function

Posted on 2004-03-24
8
466 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
 
LVL 5

Author Comment

by:cempasha
ID: 10673337
it is the ; after $contents :) just found it..
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now