By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,919 Members | 1,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,919 IT Pros & Developers. It's quick & easy.

Removing space characters from a string

P: n/a
Hi there,

How do I remove space characters from a string using PHP?

For example, the following string...

' hi there, my name is burnsy '

....has spaces, at the edges and inbetween the other characters. I know
I can use trim() to remove the outside ones but how do i remove the
inbetween ones so it will read:

'hithere,mynameisburnsy'

Any ideas? Cheers

Burnsy
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
.oO(mr_burns)
How do I remove space characters from a string using PHP?


str_replace()

Micha
Jul 17 '05 #2

P: n/a
<?php
$YourString = ' hi there, my name is burnsy ';
$YourNewString = explode(' ', $YourString);
$YourString = implode("", $YourNewString);
echo $YourString;
?>

Hope this helps,

Bernhard Enders.
Jul 17 '05 #3

P: n/a
*** mr_burns wrote/escribió (26 Oct 2004 05:05:58 -0700):
How do I remove space characters from a string using PHP?


This removes spaces, tabs, carriage returns...

preg_replace('/[[:space:]]/', '', $foo);

If you just want to get rid of actual space char:

str_replace(' ', '', $foo);
--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.