[answered]How to determine plaintext content?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

[answered]How to determine plaintext content?

Post by bdeshi »

Hey all, What's the best way (if there is) to determine if a file content is readable plaintext?
I want to display the content as is, or display the raw hex (using hexdump with r switch) if the content is not plaintext.
<pseudocode>

Code: Select all

 if (file content is textual){
  $data =  readfile($srcfile); //read in as text
 } elseif (file content is not textual)
  $data = hexdump(readfile($srcfile,b),,r); //read in data as hex
}
</pseudocode>
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: How to determine plaintext content?

Post by TheQwerty »

How about the filetype SC?

Code: Select all

help('idh_scripting_comref.htm#idh_sc_filetype');
[/size]

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: How to determine plaintext content?

Post by bdeshi »

You make me wonder about my eyesight.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: How to determine plaintext content?

Post by TheQwerty »

Whatever could you mean? :whistle:

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: [answered]How to determine plaintext content?

Post by bdeshi »

In any case, one thing led to another, I had an idea from this topic and now I [have to || need to || want to] write the whole script all over again. [ :evil: || :twisted: ]
Thanks.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: [answered]How to determine plaintext content?

Post by PeterH »

SammaySarkar wrote:In any case, one thing led to another, I had an idea from this topic and now I [have to || need to || want to] write the whole script all over again. [ :evil: || :twisted: ]
Thanks.
I think it doesn't matter:
- it's only pseudo code
- it misses an "{"
:mrgreen:

:oops: Sorry - I couldn't resist (again) :whistle:
:lol: :lol:

Post Reply