Answer the question
In order to leave comments, you need to log in
php cell phone mask
I wrote a code to search for cell numbers and bring them to the form + 7 (9**) *** - ** - ** , I can’t remove the first digit so that the number fits completely
<html>
<head>
<title>PHP</title>
</head>
<body>
<?php
$text = $_POST['comment'];
$pattern = '~(\(\d{3}\)\s\d{3}\-\d{2}\-\d{2})|(\d{3}\s\d{3}\s\d{2}\s\d{2})|(\d{10})|(\d{3}\s\d{3}\-\d{2}\-\d{2})|(8\(\d{3}\)\s\d{3}\-\d{2}\-\d{2})~s';
if(preg_match_all($pattern, $text, $match)) {
$w = implode(' ', $match[0]);
$pieces = explode(" ", $w);
$result = count($pieces);
for ($i=0; $i < $result ; $i++) {
echo preg_replace( '/^(\d{3})(\d+)$/iu', '+7($1)$2', $pieces[$i] ); // +7(921)123456789\
echo "</br>";
}
}
?>
<form action="index.php" method="post">
<p><b>Введите текст: </b><br>
<textarea name="comment" cols="40" rows="3"></textarea>
</p>
</p>
<p><input type="submit" value="Отправить"></p>
</form>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question