简体   繁体   中英

PHP equivalent of getBytes in Java

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM