473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

removing whitespace from a string?

Hi,
Here is the code I use to change whitespace from a string $test to
hypen -.

<?Php

$test="Teststring test test hay man test test test test";

// Chr(32) is ASCI code for whitespace and Chr(45) is for -

$test = str_replace(Chr(32), Chr(45), $test);

echo $test;
?>

My problem is I have to take out the whitespace completely form the
string.

I will be thankful if anyone can help me, or guide me to the function
name that can be used for this.

Thank You for help.

Jul 17 '05 #1
5 3215
On 5 Mar 2005 04:33:16 -0800, sm***********@gmail.com wrote:
Hi,
Here is the code I use to change whitespace from a string $test to
hypen -.

<?Php

$test="Teststring test test hay man test test test test";

// Chr(32) is ASCI code for whitespace and Chr(45) is for -

$test = str_replace(Chr(32), Chr(45), $test);

echo $test;
?>

My problem is I have to take out the whitespace completely form the
string.


Do exactly the same, but replace it with empty strings.

$test = str_replace(chr(32), "", $test);

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Hi,

Thanks Andy It worked

thanks a lot

bye

Jul 17 '05 #3
.oO(Andy Hassall)
Do exactly the same, but replace it with empty strings.

$test = str_replace(chr(32), "", $test);


Why the chr() function? Why no simply:

$test = str_replace(' ', '', $test);

Micha
Jul 17 '05 #4
On Sun, 06 Mar 2005 21:19:49 +0100, Michael Fesser <ne*****@gmx.net> wrote:
.oO(Andy Hassall)
Do exactly the same, but replace it with empty strings.

$test = str_replace(chr(32), "", $test);


Why the chr() function? Why no simply:

$test = str_replace(' ', '', $test);


Well, I just copied the OP's code which had the chr function, but how's this;
if all you want to do is replace the space character chr(32), can you see the
difference between:

$test = str_replace(' ', '', $test);
$test = str_replace('*', '', $test);

One of these does not do what you think :-) (Provided it survives the
copy&paste&post process...)

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
.oO(Andy Hassall)
Well, I just copied the OP's code which had the chr function, but how's this;
if all you want to do is replace the space character chr(32), can you see the
difference between:

$test = str_replace(' ', '', $test);
$test = str_replace('*', '', $test);

One of these does not do what you think :-)


I knew something like that would come up. ;)

But I assume the OP knows what he's doing and what he really wants to
replace. He should be able to hit the right key(s).

Micha
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Thomas Mlynarczyk | last post by:
Which is the simplest way to remove all whitespace from a string? Is there a simpler method than a regex replace? Or how can I tell a regex pattern to ignore all whitespace in my subject string?...
0
by: haughki | last post by:
apologies for asking this. it must have been answered before. i have really tried to find the answer elsewhere. a simple question: i'd like to remove all ignorable whitespace from my minidom...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
3
by: Ray Stevens | last post by:
Does anyone know of a Regex expression from removing extra whitespace within a string (such as 5 spaces instead of 1, etc.)?
3
by: David Pratt | last post by:
Hi. I am splitting a string on a non whitespace character. One or more whitespace characters can be returned as items in the list. I do not want the items in the list that are only whitespace (can...
8
by: starsky51 | last post by:
I'm sure it's something i'm doing wrong, I just can't see it. I've set up a simple page with the following code: <html> <head> <title>tester</title> <script language="javascript"...
2
by: beatTheDevil | last post by:
Hey guys, As the title says I'm trying to make a regular expression (regex/regexp) for use in removing the comments from code. In this case, this particular regex is meant to match /* ... */...
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
13
by: Chaim Krause | last post by:
I am unable to figure out why the first two statements work as I expect them to and the next two do not. Namely, the first two spit the sentence into its component words, while the latter two...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.