D
D
Dreaded2018-05-17 22:09:37
PHP
Dreaded, 2018-05-17 22:09:37

How to remove extra spaces when writing to the database?

I handle user input like this:

$field = strip_tags($_POST[$field]);
$field = trim($field);

If you try to enter a code with HTML tags, then the result will be written to the database in the form:
Слово1           Слово2                Слово3                   Слово4 etc...

How can you get rid of unwanted spaces?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2018-05-17
@Dreaded

$field = trim(preg_replace('/\s+/', ' ', $field));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question