php - How to get first 5 characters from string -


how first 5 characters string using php

$mystr = "hellowordl"; 

result should this

$result = "hello"; 

for single-byte strings (e.g. us-ascii, iso 8859 family, etc.) use substr , multi-byte strings (e.g. utf-8, utf-16, etc.) use mb_substr:

// singlebyte strings $result = substr($mystr, 0, 5); // multibyte strings $result = mb_substr($mystr, 0, 5); 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -