Jump to content

Reading from a file


mastermike707

Recommended Posts

Ok, there is a file that I want to read info from.  Here is an example file:
[code]
## Interface: 11100
## Title: MonkeyQuest v2.3.1
## Notes: Displays your quests for quick viewing. (http://www.toctastic.net/)
## Author: Trentin ([email protected])
## SavedVariables: MonkeyQuestConfig
## Dependencies: MonkeyLibrary
## OptionalDeps: aftt_extreme, BhaldieInfoBar
MonkeyQuest.xml
BIB\BIB_MonkeyQuest.xml
[/code]
What I want to capture into a variable is:
[code]MonkeyQuest v2.3.1[/code]
Now, heres how far I got (dosen't work):
[code]
$h2 = fopen('./'.$file.'/'.$file'.toc', 'rb');
$fd = strpbrk(strrev(substr((fread($h2, filesize('./'.$file.'/'.$file'.toc')), 30)), '';
fclose($h2);
[/code]
(.toc is the file extension) Any help would be appreciated.
Link to comment
https://forums.phpfreaks.com/topic/16223-reading-from-a-file/
Share on other sites

Something like this:
[code]<?php

$file = file_get_contents('file.toc');

// find the ## Title: line
preg_match("/## Title:(.*+)/i", $file, $matches);

// debug see the matches found
// echo '<pre>' . print_r($matches, true) . '</pre>';

// the version:
$version = $matches[1];

echo "The version/name of this script is: $version";

?>[/code]
Should work. It finds ## Title: and returns whats after that.
Link to comment
https://forums.phpfreaks.com/topic/16223-reading-from-a-file/#findComment-67142
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.