Topic awaiting preservation: Read specific line or value of a file with php (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: under your rug, |
posted 08-05-2003 00:01
Ok i've got a value lets call it $potato, which is on line 50 of a php file, but that php file has has lots of other variables and includes in it. I can't modifiy the file, but I need to read that specific variables data and echo it from another php file on my server. |
Paranoid (IV) Inmate From: France |
posted 08-05-2003 00:18
Synthetic: If the file is big you should fopen( you_file ) and retrieve the lines with a fgets( ... ) until you find $potato. If the file is smaller simply use the file( ) function, browse the previously returned array until you find $potato and voilà |
Paranoid (IV) Inmate From: under your rug, |
posted 08-05-2003 02:19
Yeah I had a similar thought but not quite sure how it would be done. Can you provide an example on how to search the array for $potato? |
Maniac (V) Mad Scientist From: Belgrade, Serbia |
posted 08-05-2003 02:33
You should take a look at file() function... |
Paranoid (IV) Inmate From: under your rug, |
posted 08-05-2003 02:40
Thanks much mr. maX that works fine, where would I be without you? Eh thats easy, I'd be still reading the darn manual scratching my head trying to figure out what it was trying to say |
Paranoid (IV) Inmate From: France |
posted 08-05-2003 03:02
Synthetic:Here is an implementation of the 2 methods I mentionned. They both use a regex to let you to assign $potato on any line. code: <? The file( ) method is faster 99.99% of the cases. |
Paranoid (IV) Inmate From: under your rug, |
posted 08-05-2003 03:10
very cool, that will be handy too, thanks poi |