I have a string that represents a temperature. This string is dynamically parsed from a website and it can contain also negative values. For example, it can be -1 C, or 2 C and so on.
I want to get only the integer value. Here is my code:
$temp_number = preg_replace("/-?[0-9]+/", '', $value);
echo "Temperature : ". $value . "Number : ".$temp_number."<br/>";
I thought that the temp_number should be the extracted number BUT it is the C for example. Here is my output.
Temperature : 0℃ Number : ℃
What should I use? I do not want to replace the string, I want to extract it.