I need to find out where the last character in the string is where the charachter is a space, and cut it off there. This is the function I’m using, but there seems to be something wrong with the if statement, but I can’t figure out what. There is certainly a space in the $text-string.
Let’s say I have a string “Hey, my name is Joh”. Then it has to be shortened to “Hey, my name is “.
$checkLastChar = false;
$text = $line[2];
while($checkLastChar != true){
for($i = 1; $i <= strlen($text); $i++)
{
if($text[strlen($tekst) - $i] == " ") {
$checkLastChar = true;
$text = substr($text, 1, strlen($text) - $i);
}
}
}
1 Answer