How to remove extra spaces when writing to the database?

Handle user input in the following way:
$field = strip_tags($_POST[$field]);
$field = trim($field);

If you try to enter the code with HTML tags, in the database record the result in the form:
Word1 Word2 Слово3 Слово4 etc...

How can you get rid of the unwanted spaces ?
June 5th 19 at 21:16
1 answer
June 5th 19 at 21:18
Solution
$field = trim(preg_replace('/\s+/', ' ', $field));
Solution? - Buddy commented on June 5th 19 at 21:21

Find more questions by tags MySQLPHP