mastermike707 Posted August 1, 2006 Share Posted August 1, 2006 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, BhaldieInfoBarMonkeyQuest.xmlBIB\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 More sharing options...
wildteen88 Posted August 1, 2006 Share Posted August 1, 2006 Use file_get_contents then eregi or preg_match to get MonkeyQuest v2.3.1 Link to comment https://forums.phpfreaks.com/topic/16223-reading-from-a-file/#findComment-67126 Share on other sites More sharing options...
mastermike707 Posted August 1, 2006 Author Share Posted August 1, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16223-reading-from-a-file/#findComment-67131 Share on other sites More sharing options...
wildteen88 Posted August 1, 2006 Share Posted August 1, 2006 Something like this:[code]<?php$file = file_get_contents('file.toc');// find the ## Title: linepreg_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 More sharing options...
mastermike707 Posted August 1, 2006 Author Share Posted August 1, 2006 Thank you VERY much. ;D Link to comment https://forums.phpfreaks.com/topic/16223-reading-from-a-file/#findComment-67175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.