If I want to extract only "7.20" from "$ 7.20", how can I do?? I have try
preg_replace("[^0-9]", "", "$ 7.20");
but it is not work. It also shows $ 7.20... There is no difference...
preg_replace('/[^.0-9]/', "", "$ 7.20");
Your regex needs to be delimited, start and end. Commonly / is used as a delimiter.
What you have above: [^0-9]
The initial [ will be interpreted as a delimiter (in pair with ] at the end).
This was looking to replace 0-9 literally at the beginning of the string.
ltrim() and a character mask of $ you can easily remove the leading unwanted characters. In addition to being brief and correct, sscanf() is more powerful than other techniques because it allows you to cast the matched substring as a float.