Jump to content


Photo

Extracting information from a file with fscanf()


  • Please log in to reply
2 replies to this topic

#1 flyhoney

flyhoney
  • Members
  • PipPipPip
  • Advanced Member
  • 846 posts
  • LocationAustin, TX

Posted 21 June 2006 - 12:55 AM

I run an open source music website where users upload project files from different music creation applications. I have been trying to write a script that will extract useful information from the project files, like application used, version number, plugins etc.. The infomation I need from the file is delimited by Ä and Á. I have been trying to use fscanf to grab the strings with the information I need out of the file, but I cannot seem to get it to work. My code is something like this:

$filename = "some/file.dat";
$file = fopen ($filename, "r");
while ($file_info = fscanf($file, "Ä%sÁ")) {
   list ($version) = $file_info;
   echo "$version<br>";
}
fclose($file);

However this is not really working. Any help would be greatly appreciated.

*I should add that I am viewing the files in a hex editor and that is how I know how the information I want is delimited.
"The enemy's gate is down." - Ender
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 21 June 2006 - 01:08 AM

try this ok.

example

$filename = "some/file.dat";
$file = fopen ($filename, "r");
while ($file_info = fscanf($file, "%Ä\s%Á\n")) {
   list ($version) = $file_info;
   echo "$version<br>";
}
fclose($file);

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 flyhoney

flyhoney
  • Members
  • PipPipPip
  • Advanced Member
  • 846 posts
  • LocationAustin, TX

Posted 21 June 2006 - 01:15 AM


Thanks for the suggestion. I tried it out, and this is the warning I get:

Warning: fscanf() [function.fscanf]: Bad scan conversion character "Ä"
"The enemy's gate is down." - Ender
error_reporting(E_ALL);          // place these two lines at the top of 
ini_set('display_errors', 1);    // the script you are debugging




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users