Hi,

I want to check a string to ensure it only contains normal characters plus a
few punctuation character, plus the Euro sign (€).

I have ereg( "[-a-zA-Z0-9.:,!+£$ €]", $string) but it fails on the euro, ie
returns true is the euro symbol is in the string.

How can I test for the presence of this character?

Thanks,

Kevin

    Try to use \xYY in your pattern where YY is the euro sign character code.

      Originally posted by jsim
      Try to use \xYY in your pattern where YY is the euro sign character code.

      Hi jsim,

      Thanks for that but still no luck. I replaced the £ with \xA3 in my regexp and it works fine, but using \xA4 (which is the € sign in iso-8859-15) the rexexp still will not accept €.

      I have set the character set on the page that called the script to iso-8859-15, but do I need to somehow tell PHP to use iso-8859-15?

      Many thanks,
      Kevin

        PHP knows nothing about character set. You can control output to the browser, but in PHP code it's not needed.
        Maybe you store wrong character in your source string?
        I test your reg and it works fine:

        $string = 'abcABC012'.chr(0xa4).'$';
        $res = ereg( "[^-a-zA-Z0-9.:,!+\\xA3$\\xA4]", $string);
        echo 0+$res;
        

        Note that in patter appears ONE slash instead of two - it will be converted by PHP right in pattern before it will be passed to ereg as argument.

          Hi,

          It still didnt work when I entered € into the form, but I changed \xA4 to \x80 and it works now. I did ord($mychar) on the input from the browser wbhic gave 128 or 80 hex for €.

          I dont understaand how this is working though, ascii 80 should be blank I think?

          Thanks,
          Kevin

            Depends on the character set you're using. Microsoft picked 0x80.

              I just tried it using netscape and it faild 🙁

              So I added in \xa4 as well as \x80 so it now works in IE and NN6, but surly there has to be a better way to do this than adding in more and more codes for the one ccharacter and hoping it works?

              Thanks,
              Kevin

                The problem is that Euro sign actually Unicode symbol and has a code 0x20AC. For use it in non-unicode (8-bits) character table it uses code 0x80 in some characters set and 0xA4 in others. So you just need to check for these two values and all will be ok.

                  hi,

                  Many thanks for all your help, I think I have it now!!!

                  Kevin

                    Write a Reply...