<?php

$s = " ddd    \r\n  bbb     ";
$n = preg_replace('~(*ANYCRLF)\h+$~m', '', $s);
echo $n;
