FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php help
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
php help [message #175291] Wed, 31 August 2011 22:23 Go to next message
bob is currently offline  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 Go to previous messageGo to next message
A is currently offline  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 Go to previous message
alvaro.NOSPAMTHANX is currently offline  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 ('/&acirc;../i', '', '&acirc;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
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: try / catch or INSERT INTO... ON DUPLICATE KEY UPDATE
Next Topic: PHP script to only be accessed by cron
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 01:24:34 GMT 2024

Total time taken to generate the page: 0.01944 seconds