trying to cut off at the last character that's a space
<p>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.</p>

<p>Let's say I have a string "Hey, my name is Joh". Then it has to be shortened to "Hey, my name is ".</p>

<pre><code>$checkLastChar = false;
$text = $line[2];

while($checkLastChar != true){
   for($i = 1; $i &lt;= strlen($text); $i++)
    {
        if($text[strlen($tekst) - $i] == " ") {
                $checkLastChar = true;
            $text = substr($text, 1, strlen($text) - $i);
        }
    }
}
</code></pre>
