Jump to content

How to fetch data from a common text file?


Recommended Posts

hi,i'm using a file stored in a common folder which is shared among many scripts.I'm using the file() function to fetch the from the file and process that info.When the txt file is stored within the same folder/directory it is running cleanly ,but when the txt file is stored in a common position , the script shows the error the file not found error.I want to store the txt file in the common folder and i want the specific code to fetch the info .How can handle this situation,..The code isFile file.phpCode:

class hardcode{ 	var $textfile;	var $name;	var $no;	function setFile($fname) {			$this->textfile = $fname;	}	 function getDetails($text) {	  			 $this->name = $text;			 foreach(file($this->textfile) as $line)					// here even i tried foreach(file($this->textfile,1) as $line) for checking the file in include paths		   			 {				   $arr = explode('--', $line);					if(strcmp(trim($arr[1]),$this->name)==0) {							  $this->no = $arr[0];					}			 }			 if(isset($this->no)) { 				  return $this->no; 			 }	 } }

This file and the txt file which contains some info is stored in a common folder.check.phpCode:

<?php 		include "file.php";		 $fileobj->setFile('accounts.txt');		 $dbobj = new dbclass;		 $nn = $fileobj->getDetails('joseph'); ?>

File.php and accounts.txt is stored in a common folder and the check.php is stored in a separate folder.How can i handle this???

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...