Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

if readable text, do something

non technical explanation:
if the characters dont have a space, it is not readable text, may be an image

problem gets more difficult, because it may be character encoding of text and image


      GIF89a@„÷ÿÿÿJJMIIKÑÑÔ‘‘“ííïïïðëëì××ØÅÅÆ©©ªž‚ÑÒؽ¾Ãxy}stxƒ„ˆ‚ƒ‡³´¸ðñõíîò×ÙàðòùbcfZ[^ÛÝãØÚàÖØÞÔÖÜíïõstw“¶·º©ª­ïðóëìïÛÜßØÙÜÖ×ÚÔÕØÏÑÖÅÇÌðò÷ïñöëíòâä鐒–ïòøíðöŸ£QRTÔÖÚÌÎÒjkmcdfïñõÚÜàØÚÞÖØܝž ðñóÀÃÈ !<=>xyzrsthij‚ƒØÙÚÔÕÖijjÂÃ訦œœšááàŽ"![YRÕÓÌÌÉ¿h^BbY?©™nÔÁŽ<7)ðܦsjQªŸ›‘vìݵÔÇ£‰v–‚ðåǬ¥’xti¾¸§ÕÑÅÓÏÄxvpðïìIA.tS‘ƒ^fðٝïØœìÕšëÔšÛƏØÍÖÁŒÔ¿‹³¢u¯€[R<SK7×ÏðÚ¡íןãΘë՞ǵ†bYBÙÆ”ìØ£ÛÈ—ÕÔØÇšðݬíÚªÛʝëØ©bZGÕÅ›ìÛ¯ðß³ëÚ¯ÚÊ¢×É¥<8.ðá»ÚÍ«ÕÊ®âØÀÖͶîäË×ϼ„€vðéאŒ‚ìæ×´°¦#<5%60"73*îêáÛØÑQNHJIGðíç¾½»ÛÚØØ×ÕÖÕÓÔÓÑsrq‚€ÁÀ¿µ´³^]]üüüúúúøøøöööõõõòòòñññïïïíííëëëèèèäääâââÛÛÛØØØÖÖÖÔÔÔÒÒÒÑÑÑÏÏÏÌÌÌÈÈÈÆÆÆÅÅŶ¶¶³³³±±±®®®¦¦¦¥¥¥¢¢¢žžž›››———•••
......


note: doesnt allways begin with GIF89a

if the space to character ratio is more than 1 space to 20 characters, do something
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Don't try to use spaces and ratios to determine this - it will not be a reliable detection.

There's something called "MIME Magic" that will examine the first few bytes of a file and try to detect what kind of file it is (every file format has a "signature"). PHP has a mime_content_type() function for doing this for you.

If it's always either an image or text, you could also use the getimagesize() function:

if( ($size = getimagesize($filename)) !== false )
{
  // $filename is an image
}
else
{
  // $filename is not an image
}
Avatar of rgb192

ASKER

note: there is no file
the input is from an array var dump
of a broken up email
and there may be text attached to an image


i could not save

  GIF89a@„÷ÿÿÿJJMIIKÑÑÔ‘‘“ííïïïðëëì××ØÅÅÆ©©ªž‚ÑÒؽ¾Ãxy}stxƒ„ˆ‚ƒ‡³´¸ðñõíîò×ÙàðòùbcfZ[^ÛÝãØÚàÖØÞÔÖÜíïõstw“¶·º©ª­ïðóëìïÛÜßØÙÜÖ×ÚÔÕØÏÑÖÅÇÌðò÷ïñöëíòâä鐒–ïòøíðöŸ£QRTÔÖÚÌÎÒjkmcdfïñõÚÜàØÚÞÖØܝž ðñóÀÃÈ !<=>xyzrsthij‚ƒØÙÚÔÕÖijjÂÃ訦œœšááàŽ"![YRÕÓÌÌÉ¿h^BbY?©™nÔÁŽ<7)ðܦsjQªŸ›‘vìݵÔÇ£‰v–‚ðåǬ¥’xti¾¸§ÕÑÅÓÏÄxvpðïìIA.tS‘ƒ^fðٝïØœìÕšëÔšÛƏØÍÖÁŒÔ¿‹³¢u¯€[R<SK7×ÏðÚ¡íןãΘë՞ǵ†bYBÙÆ”ìØ£ÛÈ—ÕÔØÇšðݬíÚªÛʝëØ©bZGÕÅ›ìÛ¯ðß³ëÚ¯ÚÊ¢×É¥<8.ðá»ÚÍ«ÕÊ®âØÀÖͶîäË×ϼ„€vðéאŒ‚ìæ×´°¦#<5%60"73*îêáÛØÑQNHJIGðíç¾½»ÛÚØØ×ÕÖÕÓÔÓÑsrq‚€ÁÀ¿µ´³^]]üüüúúúøøøöööõõõòòòñññïïïíííëëëèèèäääâââÛÛÛØØØÖÖÖÔÔÔÒÒÒÑÑÑÏÏÏÌÌÌÈÈÈÆÆÆÅÅŶ¶¶³³³±±±®®®¦¦¦¥¥¥¢¢¢žžž›››———•••‰

Open in new window


because my code editor forced me to traslitatrate


<?php
$filename='
GIF89a@„÷ÿÿÿJJMIIKÑÑÔ‘‘“ííïïïðëëì××ØÅÅÆ©©ª??ž??‚ÑÒؽ¾Ãxy}stxƒ„ˆ‚ƒ‡³´¸ðñõíîò×ÙàðòùbcfZ[^ÛÝãØÚàÖØÞÔÖÜíïõstw??“¶·º©ª­ïðóëìïÛÜßØÙÜÖ×ÚÔÕØÏÑÖÅÇÌðò÷ïñöëíòâäé?’–ïòøíðö?Ÿ£QRTÔÖÚÌÎÒjkmcdfïñõÚÜàØÚÞÖØÜ?ž ðñóÀÃÈ !<=>xyzrsthij?‚ƒØÙÚÔÕÖijjÂÃ訦œœšááà??Ž"![YRÕÓÌÌÉ¿h^BbY?©™nÔÁŽ<7)ðܦsjQªŸ?›‘vìݵÔÇ£?‰v?–‚ðåǬ¥’xti¾¸§ÕÑÅÓÏÄxvpðïìIA.?tS‘ƒ^??fðÙ?ïØœìÕšëÔšÛÆ?ØÃ?ÖÁŒÔ¿‹³¢u¯€[R<SK7×Ã?ðÚ¡íןãΘë՞ǵ†bYBÙÆ”ìØ£ÛÈ—ÕÔØÇšðݬíÚªÛÊ?ëØ©bZGÕÅ›ìÛ¯ðß³ëÚ¯ÚÊ¢×É¥<8.ðá»ÚÍ«ÕÊ®âØÀÖͶîäË×ϼ„€vðé×?Œ‚ìæ×´°¦#<5%60"73*îêáÛØÑQNHJIGðíç¾½»ÛÚØØ×ÕÖÕÓÔÓÑsrq‚?€ÁÀ¿µ´³^]]üüüúúúøøøöööõõõòòòñññïïïíííëëëèèèäääâââÛÛÛØØØÖÖÖÔÔÔÒÒÒÑÑÑÏÏÏÌÌÌÈÈÈÆÆÆÅÅŶ¶¶³³³±±±®®®¦¦¦¥¥¥¢¢¢žžž???›››———•••???‰
';
if( ($size = getimagesize($filename)) !== false )
{
  // $filename is an image
}
else
{
  // $filename is not an image
}

Open in new window





Warning: getimagesize( GIF89a@„÷ÿÿÿJJMIIKÑÑÔ‘‘“ííïïïðëëì××ØÅÅÆ©©ª??ž??‚ÑÒؽ¾Ãxy}stxƒ„ˆ‚ƒ‡³´¸ðñõíîò×ÙàðòùbcfZ[^ÛÝãØÚàÖØÞÔÖÜíïõstw??“¶·º©ª­ïðóëìïÛÜßØÙÜÖ×ÚÔÕØÏÑÖÅÇÌðò÷ïñöëíòâäé?’–ïòøíðö?Ÿ£QRTÔÖÚÌÎÒjkmcdfïñõÚÜàØÚÞÖØÜ?ž ðñóÀÃÈ !<=>xyzrsthij?‚ƒØÙÚÔÕÖijjÂÃ訦œœšááà??Ž"![YRÕÓÌÌÉ¿h^BbY?©™nÔÁŽ<7)ðܦsjQªŸ?›‘vìݵÔÇ£?‰v?–‚ðåǬ¥’xti¾¸§ÕÑÅÓÏÄxvpðïìIA.?tS‘ƒ^??fðÙ?ïØœìÕšëÔšÛÆ?ØÃ?ÖÁŒÔ¿‹³¢u¯€[R<SK7×Ã?ðÚ¡íןãΘë՞ǵ†bYBÙÆ”ìØ£ÛÈ—ÕÔØÇšðݬíÚªÛÊ?ëØ©bZGÕÅ›ìÛ¯ðß³ëÚ¯ÚÊ¢×É¥<8.ðá»ÚÍ«ÕÊ®âØÀÖͶîäË×ϼ„€vðé×?Œ‚ìæ×´°¦#<5%60"73*îêáÛØÑQNHJIGðíç¾½»ÛÚØØ×ÕÖÕÓÔÓÑsrq‚?€ÁÀ¿µ´³^]]üüüúúúøøøöööõõõòòòñññïïïíííëëëèèèäääâââÛÛÛØØØÖÖÖÔÔÔÒÒÒÑÑÑÏÏÏÌÌÌÈÈÈÆÆÆÅÅŶ¶¶³³³±±±®®®¦¦¦¥¥¥¢¢¢žžž???›››———•••???‰ ) [function.getimagesize]: failed to open stream: No error in  on line 5
You would need to save it to a temporary file to do this.

$tempfile = tempnam();
file_put_contents($tempfile,"GIF89...");
if( ($size = getimagesize($tempfile)) !== false )
{
}
else
{
}
unlink($tempfile);
Avatar of rgb192

ASKER

$filename='C:/Mail-Backup/2013/1/24/655902028-22789.eml';
if( ($size = getimagesize($filename)) !== false )
{
  // $filename is an image
  echo 'image';
}
else
{
  // $filename is not an image
  echo 'not';
}

Open in new window



output is
not image



but the .eml file has an image in it

I am using

http://www.phpclasses.org/package/3169-PHP-Decode-MIME-e-mail-messages.html

(please dont comment too much about the mime parser class, which sometimes does not function properly because I am only a beginner)

and I am not looking for a image
I am looking when a body is not readable
and when body is many special characters because there is an image

so, I would like to look at a small block of text and say, this text is not readable, do something else


for example

(if $text is readable){
echo text
}else{
do something else
}
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks for the detailed explanation about file types

now I will look at email files more closely (for viruses)