Please Help me translate this perl script into PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KENT
Forum Newbie
Posts: 8
Joined: Sat Mar 11, 2006 1:02 am

Please Help me translate this perl script into PHP

Post 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";
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Use this

Post 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
Post Reply