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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 > > |
|
|||
|
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! |
|
|||
|
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! |
![]() |
| Thread Tools | |
| Display Modes | |
|
|