Page 1 of 1

Please Help me translate this perl script into PHP

Posted: Wed Apr 26, 2006 2:35 am
by KENT
Hi you guys,
Anyone knows about perl please help me translate this perl script into php, I only know PHP and i am feeling so hard to do this. This will have done my project and I'm proud to write ur name as my teacher.
Thanks in advance :oops:

Perl script to convert a file to hex


Contributed by Kenric Mckenzie. This script may be useful when sending ringtones or graphics.

Code: Select all

open(F, "image.gif") || die $!;
$s = $hx = "";
while (read(F, $s, 1) > 0) {
    $hx .= sprintf("%02X", ord($s));
    }
close F;
print "The hex-encoded GIF file is: $hx\n";

Use this

Posted: Wed Apr 26, 2006 3:03 am
by dibyendrah
I don't know much about Perl, So this is the alternative of your code in PHP but not actual conversion.

Code: Select all

<?php
$handler = fopen("image.gif", "r") or die("File Not Found!");

while (!feof($handler)) {
	$line = fgets($handler,1024);
	$lines.= $line;
}

fclose($handler);

$hex = bin2hex($lines);

echo "Hex value of image is ".$hex."\n";
?>
Cheers,
Dibyendra