1

I read similar titles but I couldn't make it run..

Now, I have a code like this (originally ereg):

        if (preg_match("[^0-9]",$qrcode_data_string)){
        if (preg_match("[^0-9A-Z \$\*\%\+\-\.\/\:]",$qrcode_data_string)) {

I also tried using / at the beginning and end of rule but didn't work.

Any replies welcome.

Hilmi Erdem KEREN
  • 1,949
  • 20
  • 29
  • Possible duplicate of [How can I convert ereg expressions to preg in PHP?](https://stackoverflow.com/questions/6270004/how-can-i-convert-ereg-expressions-to-preg-in-php) – Toto Jun 03 '19 at 10:46

1 Answers1

0

With the preg_* functions you need delimiters around the pattern:

if (preg_match("#[^0-9]#", $qrcode_data_string)) {
#               ^      ^

From the documentation:

When using the PCRE functions, it is required that the pattern is enclosed by delimiters. A delimiter can be any non-alphanumeric, non-backslash, non-whitespace character.

Often used delimiters are forward slashes (/), hash signs (#) and tildes (~).

Community
  • 1
  • 1
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • Thank you but, as I told, I already tried that. If I use it for the first line only, it creates lot's of indexed which are invalid, If I use it for both, I get Message: QRcode : Overflow error But if I use ereg, I only see notices, but the code works. – Hilmi Erdem KEREN May 11 '12 at 22:19
  • @erdemkeren: The delimiters are **required**, as you can see by reading the documentation. It's not a case of "I'll try it, but if it doesn't work then I'll remove them". You absolutely **do** need them. The other error is something else. – Mark Byers May 11 '12 at 22:21
  • I see and understand that they are required. I read lot's of pages before asking this question here. I wanted to know if there is any other point that I miss. You say the code is true but the script is false right? – Hilmi Erdem KEREN May 11 '12 at 22:25
  • @erdemkeren: That is the only thing I can see wrong with the code you posted. See your code working online: http://ideone.com/nSOLn. There may be other errors in other parts of your code that you haven't posted. – Mark Byers May 11 '12 at 22:32
  • @erdemkeren: No I didn't miss it, but the problem with that line is *exactly* the same as with the first line: you need delimiters. Hopefully you can fix the second line yourself? – Mark Byers May 11 '12 at 22:39