Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg_replace white space

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
Hi there,
I've been trying to replace spaces but I can't see what I'm doing worng. I tried the following and both doesn't seem to be working. Is there a special way of representing white spaces in php?

Many thanks! :)

preg_replace ('/ /', '', $file_top_formatted);


preg_replace ('/\s/', '', $file_top_formatted);
 
preg_replace() returns the changed string and leaves the original string alone. I don't see in your two examples where you are accepting the returned changed string:

$somevariable = preg_replace ('/\s/', '', $file_top_formatted);

or even

$file_top_formatted = preg_replace ('/\s/', '', $file_top_formatted);



Want the best answers? Ask the best questions! TANSTAAFL!
 
Why are you using preg-replace to replace empty space.

Try:[blue]str_replace()[/blue]:
Code:
$mystring="This  string  has spac  es";
$output=str_replace(" ","x",$mystring);

//[orange]oupput: Thisxxstringxxhasxspacexxes[/orange]

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top