Jump to content

Archived

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

mastermike707

Reading from a file

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 (trentin@toctastic.net)
## 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.

Share this post


Link to post
Share on other sites
Use file_get_contents then eregi or preg_match to get MonkeyQuest v2.3.1

Share this post


Link to post
Share on other sites
The only problem with that is that MonkeyQuest is just a example, the MonkeyQuest could just as easily be ChickenSoup. I only want to capture the Title portion into a var.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.