I have a little problem. I am trying to convert a string like "1,234" to a number: 1234 I can’t get there. The string is cleared from the website. Perhaps there is no place? Because I tried methods like str_replace and preg_split for space and nothing. Also (int) $ abc accepts only the first digit (1). If anyone has an idea, I would love to! Thank!
Here's how I would handle it ...
<?php $string = "Here! is some text, and numbers 12 345, and symbols !£$%^&"; $new_string = preg_replace("/[^0-9]/", "", $string); echo $new_string // Returns 12345 ?>
intval(preg_replace('/[^0-9]/', '', $input))
- , , , - , .
- str_replace.
$iInt = (int)str_replace(array(" ", ".", ","), "", $iInt);
$str = "1 234"; $int = intval(str_replace(' ', '', $str)); //1234