How to strip all spaces out of a string in php

→ Are you a new visitor? Please visit the page guidance for new visitors ←

How to strip all spaces out of a string in php

You have a string stored in a PHP variable, and you want to eliminate all whitespaces or spaces from that string with PHP, not only from the beginning or the end of the string.

Scenario

Solution for spaces

Solution for whitespaces

Difference between spaces and whitespaces

Space is the regular space character between words, whitespace is any kind of space in text: regular space, new line, tab, etc. Their ASCII representation differs one from another, this is why we need different solutions for them.

Request an article ←