2004-01-20 kl. 10.41 skrev Dagfinn Reiersøl:


[EMAIL PROTECTED] wrote:

$string = 'ab12345-1';
if (preg_match('/^([a-zåäö]{2,3})([0-9]{4,5}(\-[0-9]{1,2}){0,1})$/i',
$string,
$m='')) {
  echo $m[1]; // -> ab
  echo $m[2]; // -> 12345-1
}

g. martin luethi

You can replace {0,1} with a question mark and [0-9] with \d (digit). Also, and I
think this is not in the PHP documentation, you can use POSIX character classes
inside the brackets. If you want to match alphabetical characters including
the Swedish and various other international ones like æ or ü, you can use [:alpha:].
You may not need it in this example, but it's excellent for internationalized regex matching.


if (preg_match('/^([[:alpha:]]{2,3})(\d{4,5}(\-\d{1,2})?)$/i',

Have been playing around a bit with this code, but I can't get it to work with international characters… For example, if I feed my function:


function split_bokid($bokid)
{
if (preg_match('/^([a-zåäö]{2,3})([0-9]{4,5}(\-[0-9]{1,2}){0,1})$/ i',$bokid,$m='')) {
return $m;
}
else
{
return false;
}
}


returns, with the following code:

        $test = split_bokid("ääö123");
        echo $test[1];
        echo $test[2];

the values:
        ŠŠš
        12345

So, is there any way I can set the encoding on the incoming values, which will come from url's and databases, so that they don't fuck up?

Sincerely,

Victor
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to