How to remove number from right string in php?
The function will remove numeric characters at the end of the string.
1. Code:
<?php function removeNumericFromRightString($str){ $i = strlen($str) - 1; while (is_numeric($str[$i])) { $i--; if ($i == 0) { break; } } if ($i > 0) { return substr($str, 0, $i + 1); } return $str[$i]; } $str = "Soltuts.com is providing PHP tutorials 12345"; echo(removeNumericFromRightString($str)); ?>
2. Example:
Input:
"Soltuts.com is providing PHP tutorials 12345"
Output:
Soltuts.com is providing PHP tutorials