Jump to content


Photo

Reading from a file


  • Please log in to reply
4 replies to this topic

#1 mastermike707

mastermike707
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 04:15 PM

Ok, there is a file that I want to read info from.  Here is an example file:
## 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
What I want to capture into a variable is:
MonkeyQuest v2.3.1
Now, heres how far I got (dosen't work):
$h2 = fopen('./'.$file.'/'.$file'.toc', 'rb');
$fd = strpbrk(strrev(substr((fread($h2, filesize('./'.$file.'/'.$file'.toc')), 30)), '';
fclose($h2);
(.toc is the file extension) Any help would be appreciated.
[url=http://www.mastermike707.com/new/][/url]

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 04:17 PM

Use file_get_contents then eregi or preg_match to get MonkeyQuest v2.3.1

#3 mastermike707

mastermike707
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 04:22 PM

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.
[url=http://www.mastermike707.com/new/][/url]

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 04:36 PM

Something like this:
<?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";

?>
Should work. It finds ## Title: and returns whats after that.

#5 mastermike707

mastermike707
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 August 2006 - 05:18 PM

Thank you VERY much.  ;D
[url=http://www.mastermike707.com/new/][/url]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users