Question : remove word from string php
Answered by : rohit-ghodadra
<?php
// IF ONLY CHARACTER IN STRINGS
$str = "Hello PHP";
echo str_replace("PHP","",$str); // its remove PHP From string
//Output = Hello;
// IF NUMARIC OR CHARACTERS IN STRING AND YOU NEED ONLY STRING
$strInt = "124Peter56";
echo $words = preg_replace('/[0-9]+/', '', $strInt); // it remove integer from string
// Output = Peter;
// IF NUMARIC OR CHARACTERS IN STRING AND YOU NEED ONLY INTEGERS
$strInt = "124Peter56";
echo $res = preg_replace("/[^0-9]/", "", $strInt ); // It Remove all string
// Output = 12456
?>
Source : | Last Update : Sat, 02 Apr 22
Question : replace all numbers in string php
Answered by : mike-p-sinn
$words = preg_replace('/[0-9]+/', '', $words);
Source : https://stackoverflow.com/questions/14236148/how-to-remove-all-numbers-from-string | Last Update : Wed, 28 Oct 20