Page 1 of 1

preg_match help with british pound sign

Posted: Mon Aug 30, 2004 9:28 am
by numinor
i pull a field from a request variable which has a british pound sign in it "£", then i can't preg_match it at all...

echo preg_match("/£/", $var) ? "YES" : "NO";

if i implicitly do $var .= "£" before it it matches that.. but not the other one that maybe be in the variable before.

any help?

Posted: Mon Aug 30, 2004 9:34 am
by markl999
If you echo $var (the one from the request) what does it output?

Posted: Mon Aug 30, 2004 9:36 am
by numinor
the one from the request outputs as "£", and the one i implicitly input to test it is "£"

:\

cheers for the speedy reply

Posted: Mon Aug 30, 2004 9:41 am
by markl999
Hmm..ok, how exactly are you setting $var? i.e which request variable is it comming from?

Posted: Mon Aug 30, 2004 9:45 am
by numinor
it's just from $_REQUEST['varname'];

Posted: Mon Aug 30, 2004 9:47 am
by markl999
And where is varname coming from? ;)
I'm just trying to get at why there's a strange char/control char in there, the 'Â' bit. If you manually set $var = '£'; the the preg_match works ok too, so just trying to work backwards to find the root of the problem :o

Posted: Mon Aug 30, 2004 9:51 am
by numinor

Code: Select all

$short = $_REQUESTї'shortbio'];
        $long  = $_REQUESTї'longbio'];
        
        $short = preg_replace("/(\n\r|\n)/", "<br />", $short);
        $long  = preg_replace("/(\n\r|\n)/", "<br />", $long);
        $short = preg_replace("/\r/", "", $short);
        $long =  preg_replace("/\r/", "", $long);

        $short = preg_replace("/£/", "", $short);
        $long = preg_replace("/£/", "", $long);
here's the code... if you print $short or $long before the last preg_replace calls it definatly HAS the £ sign in there (if you pass it in one of the request vars)... but no replacing takes place :\

cheers

Posted: Mon Aug 30, 2004 9:59 am
by markl999
Well, still sounds like something dodgy in the input, ie the original $_REQUEST vars, so maybe var_dump($_REQUEST); and see what the original values coming in are.
I'm not sure why you're using those preg_replace lines any way and not just nl2br() and str_replace() ?

Posted: Mon Aug 30, 2004 10:02 am
by numinor

Code: Select all

<?php
$a = "£";
echo "A:$a";
?>
i tried this... still outputs the weird £ thing

i'm a sucker for using the preg_ functions... and i didn't know there was a nl2br function.. cheers.

Posted: Mon Aug 30, 2004 10:24 am
by numinor
problem FIXED :D

after long searching... i found a hex value for the pound sign which actually worked... tried some that some sites said was the right one but wasn't...

using \xa3 as the £ character works..

thanks anyways...