2
Guys with the help of the stack people here, I set up a function where I do the processing of a string.
I’ll post the code and explain the problem.
Function:
function mb_str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT, $encoding = "UTF-8") {
$diff = strlen($input) - mb_strlen($input, $encoding);
return str_pad($input, $pad_length + $diff, $pad_string, $pad_type);
}
Example, when I call the function so:
echo mb_str_pad("ESPERANÇA", 15, "#");
She returns to me:
ESPERANÇA######
Well, the problem starts when you put in a word that contains more than 15 letters, I need her to cut the word. Example of what it should look like:
echo mb_str_pad("ESPERANÇAaaaaaaaaaaa", 15, "#");
You have to return like this:
ESPERANÇAaaaaaa
In other words, if you pass 15 characters, you have to cut and ignore everything on the right.
Can someone help me with that?
Well that way it almost worked, but I need to capture the value that I pass when I call the function
mb_str_pad
for in every place I call her, he possesses a different value.– Hugo Borges
blz put it like this
substr($str, 0, $pad_length);
– Hugo Borges
Well, I’m glad I helped in some way. :)
– alan