PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function rtrim_word(string $haystack, string $needle): string { if (!str_ends_with($haystack, $needle)) { return $haystack; } return substr_replace($haystack, '', -strlen($needle)); } function right_trim(string $haystack, string $needle): string { if (str_ends_with($haystack, $needle)) { return substr($haystack, 0, -strlen($needle)); } return $haystack; } var_export( rtrim_word('this is a hamstrïng', 'strïng') ); var_export( right_trim('this is a hamstrïng', 'strïng') );
Show:  
Copy Clear