title: How to convert string to UTF-8 byte array in PHP for Java BufferedInputStream.read()?
body: <p>I need to make Java socket client and PHP-cli socket server and need to send client a UTF-8 encoded byte array and make so that Java BufferedInputStream.read() function would accept it.</p>
  
  <p><strong>[SERVER]</strong></p>
  
  <pre><code>$input = socket_read($client[$i]['sock'],1024,PHP_BINARY_READ);
  if($input==null || $input===FALSE) {unset($client[$i]);}
  socket_write($client[$i]['sock'], unpack('C*', utf8_encode($input)));
  </code></pre>
  
  <p><strong>[CLIENT]</strong></p>
  
  <pre><code>out = new BufferedOutputStream(socket.getOutputStream());
  out.write(str.getBytes("UTF-8"));
  out.flush();
  
  in = new BufferedInputStream(socket.getInputStream());
  byte[] b = new byte[]{};
  str = new String(in.read(b), "UTF-8");
  System.out.println("[SOCKET] Server: " + str);
  </code></pre>
  
  <p>So i need a PHP analogue of
  <code>String.getBytes("UTF-8");</code><br>
  Thanks for feedback!</p>