I have a small problem. I am tryng to convert a string like "1 234" to a number:1234 I cant't get there. The string is scraped fro a website. It is possible not to be a space there? Because I've tried methods like str_replace and preg_split for space and nothing. Also (int)$abc takes only the first digit(1). If anyone has an ideea, I'd be greatefull! Thank you!
parseInt( ) The function returns an integer parsed from the given string. If the first argument is not a string, it is converted to one automatically using ToString() . Either way, any leading whitespace is ignored.
We can convert String to an int in java using Integer. parseInt() method. To convert String into Integer, we can use Integer. valueOf() method which returns instance of Integer class.
This is 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
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With