I’m trying to modify a variable from a form.
I want to get rid of any “,” but keep the “.” while changing it to “%2e”
$price = '6,000.65';
//$price = preg_replace('.', '%2e', $price);
$price = urlencode($price);
echo $price;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is the exact result from your question:
But why would you urlencode it…? If you want to strip unallowed characters (everything but digits and a dot), use the next function:
Alternatively, you can convert the string into a floating point number and use
number_format()to format it nicely.Third option, works in a similar way.
%is a special character forsprintf, marking a conversation specification..2tells it to have two decimals andftells it’s a floating point number.References: