Sum of strings in PHP and JavaScript

0

I came across this problem and got into conflict, when using '+' in JavaScript it "joins" and in PHP it gives me a number (Hi?), good it is to fit JavaScript with PHP , see:

alert(CryptoJS.SHA1('ABCDE' + 'ABCD'.substr(0, 32)));
result: 64b9885c4ab720cabee37f0011aeb06efa27f9b3

Available here.

In PHP I execute the "same" thing, but it returns something different:

echo SHA1('ABCDE' + substr('ABCD', 0, 32));
result: b6589fc6ab0dc82cf12099d1c2d40ab994e8410c

Why ? What is the explanation for this and how to adjust JavaScript?

    
asked by anonymous 20.04.2015 / 21:46

1 answer

4

PHP and javascript have different operators for the concatenate strings operation.
In javascript, use " + "; in PHP, use ". "

echo SHA1('ABCDE' . substr('ABCD', 0, 32));
    
20.04.2015 / 21:51