1

У меня есть input number

<input type="number" min="0" max="1000" step="0.001" name="data[contribution][]">

как мне ввести его значение чрез запятую, к примеру (125,365)

Сейчас выводится так <?=$data['contribution']?> и соответственно значение через точку (125.365)

Я ничего не смыслю в PHP, помогите с данным вопросом

2 ответа 2

1

В php есть функция для таких задач: https://www.php.net/manual/ru/function.number-format.php Вот для вашей задачи пример из мануала:

$number = 1234.56;
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56
0
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<form action="/test.php" method="post">
    <input type="number" min="0" max="1000" step="0.001" name="number">
    <button type="submit">Go!</button>
</form>
</body>
</html>
<?php

if (isset($_POST['number'])){
    $number = str_ireplace('.',',',$_POST['number']);
    echo $number;
}

https://www.php.net/manual/ru/function.str-ireplace.php

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.