|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi,
I am currently trying to open a text file. I then have a function that will search for an item that i specify in my .php3 file and it goes through the function and returns the price. However I am getting an error and it seems that the initial opening of the text file is not carrying through to the function. Can someone please help... here is my code and the error I am getting: Code: <script language="php"> $myFile = fopen("hardware.txt","r"); function getPrice($searchParam) { // $myFile = fopen("hardware.txt","r"); // when i include this line the erro goes away, however performance is also decreased dramatically. page becomes very slow to load. while(!feof($myFile)) { $myLine = fgets($myFile, 255); list( $code, $product, $price, $street, $supplier ) = split("[|]", $myLine); if($code == $searchParam) { echo "$pricen"; } } return("Call!"); } </script> some info in here... <script language="php"> getPrice('TURBO02'); print ("<BR>"); </script> more info in here... <script language="php"> fclose($myFile); </script> Error: Warning: Unable to find file identifier 0 in /import/clients/m/microway/www.microway.com.au/htdocs/catalog/list_comm.php3 on line 17 Line 17 happens to be this: while(!feof($myFile)) { Please help!!! Thanks in advance! Dave |
|
#2
|
|||
|
|||
|
If you open the file outside of the function but want to manipulate the file in the function you'll have to pass the file id as a parameter of the function or declare it global. Otherwise it won't be available to the function.
|
|
#3
|
|||
|
|||
|
sorry for my ignorance but im just new to php... could you possible show me how I would define it globally??
|
|
#4
|
|||
|
|||
|
Try:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> $fd=1; function function_name () { print isset($fd); // Local variable.. Not defined. global $fd; print isset($fd); // Global variable.. defined on line 1 } function_name(); [/code] --- Dist - dist@clan-station.org - Founding member of Clan Station [This message has been edited by Dist (edited April 18, 2000).] |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Please help!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|