1

I have the below Java code:

String Str1 = new String("Welcome to Tutorialspoint.com");
System.out.println(Str1.toString().getBytes("UTF-8"));

The output on a 64-bit Windows 7 machine is: "[B@7041825e".

What would be the above code's PHP equivalent?

msrd0
  • 7,816
  • 9
  • 47
  • 82
user723826
  • 83
  • 1
  • 6
  • Its not as straight forward, and takes a bit of data mangling, but you can reasonably fake it with pack() and unpack(). See http://stackoverflow.com/questions/885597/string-to-byte-array-in-php – Uberfuzzy Aug 27 '14 at 14:32
  • The `toString()` is redundant (Str1 is already a String), and the result is useless. What are you planning to do with the hashcode of a byte array? – Kayaman Aug 27 '14 at 14:41

2 Answers2

2

There isn't. PHP doesn't have a distinction between strings and a bunch of bytes.

jou
  • 5,824
  • 3
  • 22
  • 24
-1

You may use strlen() for that purpose.

In your case, mb_strlen() will do.

... for more reading: http://php.net/manual/en/function.mb-strlen.php

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
Jonathan
  • 1,542
  • 3
  • 16
  • 24