The rtrim function removes whitespace (or other characters) from the end of a string.

    
    $sentence = "Hello World!   ";

    $sentenceTrim = rtrim($sentence);

    echo $sentenceTrim;
    // Hello World!