Speed up development with full-stack environments for every branch.

Learn More

How to get string length, find string, split string and truncate [mbstring and PHP]

101 Runs 425 Views 61 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php

/*
 * PHP mbstring - How to get string length, find string, split string and truncate
 */

//This illustrates how usefull is mb_strlen
$str = "åèö";
echo "strlen result : " . strlen($str) . "<br />";
echo "mb_strlen result : " . mb_strlen($str, 'UTF-8');
echo "<br /><br />";

//Find position of first occurrence of string in a string
echo mb_strpos("This is a demö string", "demö");
echo "<br /><br />";

//Split multibyte string and returns the result as an array. 
$split = mb_split("あ", "oneあtwoあthree");
print_r($split);
echo "<br /><br />";

    
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).