/    Sign up×
Community /Pin to ProfileBookmark

Totaly remove spaces

I have a form field and it has come to my attention that some people put spaces in the field. How can I totaly strip all spaces from a text string.
EG.

[code=php]$text = “A b cd e f g”;
stripspaces($text);
echo $text //Echos Abcdefg[/code]

How can I achieve this?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@PezmcauthorMar 03.2007 — I have already tried this but it dont work[code=php] $initials = MakeSafe(strtoupper(trim($_POST["initials"])));
$initials = str_replace(" ", "", $initials); [/code]
Copy linkTweet thisAlerts:
@PezmcauthorMar 03.2007 — oh and makesafe is this[code=php]function MakeSafe($unsafestring) {
if (!get_magic_quotes_gpc())
{
return mysql_escape_string($unsafestring);
}
return htmlentities($unsafestring);
} [php]
Copy linkTweet thisAlerts:
@Paul_JrMar 03.2007 — Your code works fine for me...
Copy linkTweet thisAlerts:
@PezmcauthorMar 03.2007 — for me it echoes "A b c d e f g"
Copy linkTweet thisAlerts:
@Paul_JrMar 03.2007 — Hmmm... strange. Can you post a bigger piece of the code (all of it?)?
Copy linkTweet thisAlerts:
@PezmcauthorMar 05.2007 — above is the whole code the rest is just the same thing for other form elements.
Copy linkTweet thisAlerts:
@rcracingfan24Mar 05.2007 — $text = str_replace(' ', '', $text);
×

Success!

Help @Pezmc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...