php help [message #175291] |
Wed, 31 August 2011 22:23 |
bob
Messages: 11 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
I need some php help.
I need to replace â followed by two unknown characters with an
empty string.
I tried this, but it's not quite right:
$newstring=preg_replace ("/â??/i", "",$newstring);
Any ideas?
|
|
|
Re: php help [message #175292 is a reply to message #175291] |
Wed, 31 August 2011 22:48 |
A
Messages: 17 Registered: June 2011
Karma: 0
|
Junior Member |
|
|
> $newstring=preg_replace ("/â??/i", "",$newstring);
You didn't specify what these unknown characters should be.
I am guessing non-whitespace. In that case this would be appropriate:
$newstring=preg_replace ('/â\S\S/i', '',$newstring);
So that would match:
âabcer
But wouldn't match:
â asdasd
or...
âa sdasd
Note the "single" quotes (apostrophe) instead of your double quotes (that
don't need to escape backslash).
If you want to match anything then use:
$newstring=preg_replace ('/â../i', '',$newstring);
That would match any case of the above.
|
|
|
Re: php help [message #175297 is a reply to message #175291] |
Thu, 01 September 2011 08:44 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
El 01/09/2011 0:23, bob escribió/wrote:
> I need some php help.
>
> I need to replaceâ followed by two unknown characters with an
> empty string.
>
> I tried this, but it's not quite right:
"Not quite right". Nice description. As useful as "Does not work" :)
>
>
> $newstring=preg_replace ("/â??/i", "",$newstring);
The "?" symbol means "any character" in Windows wildcards but not in
regular expressions. You want "." instead:
<?php
var_dump( preg_replace ('/â../i', '', 'âabKeep Me!') );
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|