[SOLVED] preg_match help with british pound sign

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
numinor
Forum Newbie
Posts: 6
Joined: Mon Aug 30, 2004 9:28 am

preg_match help with british pound sign

Post 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?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

If you echo $var (the one from the request) what does it output?
numinor
Forum Newbie
Posts: 6
Joined: Mon Aug 30, 2004 9:28 am

Post by numinor »

the one from the request outputs as "£", and the one i implicitly input to test it is "£"

:\

cheers for the speedy reply
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Hmm..ok, how exactly are you setting $var? i.e which request variable is it comming from?
numinor
Forum Newbie
Posts: 6
Joined: Mon Aug 30, 2004 9:28 am

Post by numinor »

it's just from $_REQUEST['varname'];
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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
numinor
Forum Newbie
Posts: 6
Joined: Mon Aug 30, 2004 9:28 am

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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() ?
numinor
Forum Newbie
Posts: 6
Joined: Mon Aug 30, 2004 9:28 am

Post 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.
numinor
Forum Newbie
Posts: 6
Joined: Mon Aug 30, 2004 9:28 am

Post 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...
Post Reply