Quick String Query...

This is a discussion on Quick String Query... within the PHP Language forums, part of the PHP Programming Forums category; I have been using PHP for a while now, although my knowledge of the inbuilt functions is pretty lacking. I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-30-2003
Jamie Wright
 
Posts: n/a
Default Quick String Query...

I have been using PHP for a while now, although my knowledge of the inbuilt
functions is pretty lacking. I am trying to remove a 'space' from the middle
of a string. I reckon I could split the string at teh space, trim each
string then join them, but this seems a little long winded. Is there a
command to remove certain charachters? Or even better white space? I've
searched the PHP manual with little luck.

Any help would be appreciated.

Jamie


Reply With Quote
  #2 (permalink)  
Old 06-30-2003
Jason Dumler
 
Posts: n/a
Default Re: Quick String Query...

Jamie,

Try the "str_replace" or "preg_replace" functions.

str_replace is a straight forward string replacement function, while
preg_replace lets you use perl regular expressions to replace strings
inside other strings.

Jason

Jamie Wright wrote:
> I have been using PHP for a while now, although my knowledge of the inbuilt
> functions is pretty lacking. I am trying to remove a 'space' from the middle
> of a string. I reckon I could split the string at teh space, trim each
> string then join them, but this seems a little long winded. Is there a
> command to remove certain charachters? Or even better white space? I've
> searched the PHP manual with little luck.
>
> Any help would be appreciated.
>
> Jamie
>
>


Reply With Quote
  #3 (permalink)  
Old 06-30-2003
James Sleeman
 
Posts: n/a
Default Re: Quick String Query...

Jamie Wright wrote:

> I have been using PHP for a while now, although my knowledge of the
> inbuilt functions is pretty lacking. I am trying to remove a 'space' from
> the middle of a string. I reckon I could split the string at teh space,


$string = preg_replace('/\s+/', '', $string);

--
James Sleeman
Gogo:Code http://www.gogo.co.nz/
Email domain : gogo.co.nz see user in from header!
Reply With Quote
  #4 (permalink)  
Old 06-30-2003
James Sleeman
 
Posts: n/a
Default Re: Quick String Query...

Jamie Wright wrote:

>> $string = preg_replace('/\s+/', '', $string);

>
> Cheers for that. You wouldn't care to explain the /\s+/ would you? Does
> this mean 'space'?


Yes, that is a regular expression, \s means whitespace and + means one or
more, so the expression matches one or more whitespace characters.

Regular Expression Syntax :
http://nz.php.net/manual/en/pcre.pattern.syntax.php

--
James Sleeman
Gogo:Code http://www.gogo.co.nz/
Email domain : gogo.co.nz see user in from header!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:25 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0