Reputation: 6405
I need a simple function(e.g function_cut) to cut from a variable characters if the number of characters is bigger than 14. For example the current $user has 18 characters and I need to cut 4 of them (doesn't matter which one).
$user = "abc123abc123abc123"; $user = function_cut($user);
Upvotes: 0
Views: 124
Reputation: 9387
All the solutions are fine, but if you have UTF8 data, you should use the multibyte versions of the function, namely mb_substr:
function cut($str){
return mb_substr($str, 0, 14);
}
Upvotes: 1
Reputation: 46692
<?php
$user = "abc123abc123abc123";
$user = substr($user, 0, 14);
?>
Upvotes: 1