Reputation: 2081
I came across this line of code in an application I am revising:
substr($sometext1 ^ $sometext2, 0, 512);
What does the ^
mean?
Upvotes: 8
Views: 4122
Reputation: 1
^
matches the starting position within the string. In line-based tools, it matches the starting position of any line.
Upvotes: 0
Reputation: 15234
In PHP, ^
means 'bitwise XOR'. Your code XORs together two strings, then returns at most the first 512 characters.
In other words it does this:
return (at most the first 512 characters of (someText1 XOR someText2))
Upvotes: 2
Reputation: 39929
$a ^ $b means bits that are set in $a or $b, but not both, are set.
Upvotes: 7
Reputation: 1039200
It's a bitwise operator.
Example:
"hallo" ^ "hello"
It outputs the ASCII values #0
#4
#0
#0
#0
('a'
^ 'e'
= #4
).
Upvotes: 6
Reputation: 411012
^
is the bitwise exclusive OR operator. For each bit in a value, it looks to see if that bit is the same in the other value; if it is the same, a 0 is output in its place, otherwise a 1 is output. For example:
00001111
^ 01010101
--------
01011010
Upvotes: 8
Reputation: 346407
That's the bitwise OR operator - in PHP, it also applies to strings.
Upvotes: 2
Reputation: 56408
It's the XOR (exclusive-or) operator. For strings it's used as simple encryption.
Upvotes: 2