Reputation: 3214
I have these strings returned in variable $item_data
..
180 - 190 (cm)
20 (litres)
How do i remove (cm)
or (litres)
from the string and only allow numbers and the dash?
$item_data = preg_replace('/[^a-zA-Z]+/', '', $item_data);
Upvotes: 0
Views: 98
Reputation: 22532
you can use also
$str="180 - 190 (cm)";
echo $result = preg_replace('/[^\d-]+/', '', $str);
output:180-190
Upvotes: 1
Reputation: 3709
This should work :)
$item_data = preg_replace('/[^0-9-]+/', '', $item_data);
Upvotes: 3