Great approach to remove all numbers from a string in PHP

Member

braden_wiegand

by braden_wiegand, in category: PHP , 7 months ago

Great approach to remove all numbers from a string in PHP via regular expression. PRO level regular expression in PHP πŸ˜€ Instead of simple [0-9] or \d look:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$words = preg_replace('/0/', '', $words ); // remove numbers
$words = preg_replace('/1/', '', $words ); // remove numbers
$words = preg_replace('/2/', '', $words ); // remove numbers
$words = preg_replace('/3/', '', $words ); // remove numbers
$words = preg_replace('/4/', '', $words ); // remove numbers
$words = preg_replace('/5/', '', $words ); // remove numbers
$words = preg_replace('/6/', '', $words ); // remove numbers
$words = preg_replace('/7/', '', $words ); // remove numbers
$words = preg_replace('/8/', '', $words ); // remove numbers
$words = preg_replace('/9/', '', $words ); // remove numbers


Facebook Twitter LinkedIn Telegram Whatsapp Pocket

no answers