Hey guys, for a school project, I need to read a .8xp file with PHP. Of course, I can use file_get_contents( but that gives me strings, and I want the hex/decimals into an array. Now the token "Disp " becomes instead of $DE (or 222). Any idea how to do that? Thanks in advance! Smile
PT_ wrote:
Hey guys, for a school project, I need to read a .8xp file with PHP. Of course, I can use file_get_contents( but that gives me strings, and I want the hex/decimals into an array. Now the token "Disp " becomes instead of $DE (or 222). Any idea how to do that? Thanks in advance! Smile

I don't entirely understand your question. Do you want to be able to read tokenized data out of a program file, like being able to get "Disp", or do just want to open it like any other binary file? For the first, this might prove useful: https://github.com/adriweb/tivars_lib
Indeed my tivars_lib code should help you do that in PHP.

The tests.php file is full of example, but basically, you'd need to do:


Code:
<?php

include_once "src/autoloader.php";
use tivars\TIVarFile;

$testPrgm = TIVarFile::loadFromFile('the/path/to/your/program.8xp');
$testPrgmContent = $testPrgm->getReadableContent();


Then the program, as a human-readable string, is in $testPrgmContent.
Unfortunately, this is not exactly what I want Sad
Your library converts the input to readable string, which is nice, but when I display $testPrgmContent[0], it displays "F" and I need the first token, which is For(. Still a good library though! Good Idea

Any other ideas about how to convert the input to tokens (or corresponding hex)? Thanks in advance! Smile
UPDATE: I found a way to read it, better said, the hex. I got it from this. This is my code:

Code:
<?php
   $handle = @fopen("TEST.8xp", "r");
   if ($handle) {
      while (!feof($handle)) {
         $buffer[] = fgets($handle, 400);
      }
      fclose($handle);
      // $buffer[0][0] = chr(hexdec("FF")); // set the first byte to 0xFF
      echo bin2hex($buffer[2][7]);
   }
Another option for an open-source TI token manipulation library would be elfprince13's excellent TITokens, which works with many different languages (and can be used for many different purposes, including syntax highlighting, tokenization, etc). Pro-tip from SAX: to get started, execute https://github.com/elfprince13/TITokens/blob/master/build.sh .
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement