/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Hex my PHP?!

Heya folks, Im trying to build a stream of Hex values for a socket.

This works fine for example..

[CODE]$packet1 = “x32”;[/CODE]

If you echo $packet1 you would get “2”.

But now the following…

[CODE]$packet2 = ‘x32’;[/CODE]

Note the use of single quotes insted of double.

Now if you echo $packet2 you get “x32”, how would I go about typecasting $packet2 to be like $packet1?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@kevinkorbJun 02.2006 — Use the single quotes???? What is your question????
Copy linkTweet thisAlerts:
@MrCoderauthorJun 02.2006 — I knew somebody would say that..

Ok, let me explain more then *sigh*

Lets say for example I have the following code

[CODE]
$in = "x32x2ex33x2ex30x00x00x00x00x00x00x00x00x00x00x00";
$in .= GenKey(64);

function GenKey($length)
{
$key = "";
$table = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for ( $count=0; $count<$length; $count++ )
{
$num = rand(0, 61);
$key .= sprintf("x%02x",ord($table[$num]));
}
return $key;
}
[/CODE]


This code outputs the first 16 values stored using double quotes correctly, but the remaining values returned by GetKey are stored in plain text, not as hex.
Copy linkTweet thisAlerts:
@MrCoderauthorJun 02.2006 — nm, got it working.
Copy linkTweet thisAlerts:
@chazzyJun 02.2006 — I'm a little curious how you got this.
Copy linkTweet thisAlerts:
@MrCoderauthorJun 03.2006 — Using Pack and Unpack mate.
Copy linkTweet thisAlerts:
@chazzyJun 04.2006 — ahhh chip chip cheerio and all that.
×

Success!

Help @MrCoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...