Masi Masi - 1 year ago 84
PHP Question

To strip whitespaces inside a variable in PHP

How can you strip whitespaces in PHP's variable?

I know this comment
I would like to have a similar tool like

for PHP such that I can run simply

tr -d " " ""

I run unsuccessfully the function

$tags_trimmed = php_strip_whitespace($tags);

I run the regex function also unsuccessfully

$tags_trimmed = preg_replace(" ", "", $tags);

Answer Source

To strip any whitespace, you can use a regular expression

$str=preg_replace('/\s+/', '', $str);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download