PHP: preg_match; Failed to match character £

I really ruined my brains over this, because for life I can’t understand what the problem is.

I have some data that I want to run a regular expression on. For reference, the source document is encoded in iso-8859-15, if that matters.

Here is a function using a regular expression:

if(preg_match("{£\d+\.\d+}", $handle)) // { echo 'Found a match'; } else { echo 'No match found'; } 

No matter what I try, I cannot make it fit. I tried just looking for the £ character. I went through my regex and there are no problems there. I even pasted the source data directly into the regular expression tester, and it found a complete match for what I'm looking for. I just don't understand why my regex doesn't work. I looked at the raw data in my string, which I am looking for, and the symbol £ exists as clearly as day.

I get the feeling that there is some kind of encoded character there that I just don’t see, but no matter how I output the data, all I see is the £ symbol, but for some reason it is not recognized.

Any ideas? Is there an absolute method of viewing raw data in a row? I tried var_dump and var_export, but I feel that something is not quite right, since var_export displays data in another language. How can I see what is "really" in my variable?

I even saved the contents in a txt file. E is. There should be no reason why I could not find it with my regular expression. I just do not understand. If I create a line and insert the exact bit of the test, then my regular expression should match, it finds a match without any problems.

Truly incomprehensible.

+4
source share
2 answers

You can always convert the letter:

 $string = '£100.00'; if(preg_match("/\xa3/",$string)){ echo 'match found'; }else{ echo 'no matches'; } 
+3
source

You can include any character in your regular expression if you know the hexadecimal value. I think the value is 0A3H, so try the following:

  \xa3 // Updated with the correct hex value 
+2
source

All Articles