Match the strings in array

I got a trouble in matching the strings in yii. i tried to use the javascript method, but i didn’t find it. besides, i want to make it up with preg_match, but i don’t know the way it is… Is anyone could help me? Thanks


Could you provide an example of exactly what you’re trying to achieve? Code always helps.

Let’s say, i have string1 & string 2 (in the same model), which string1 has 7 digits and string2’s 2 digits.

then i want to match them together, where 2 of the string1’s beginning digits must be same as the string2. I tried this code in model >>

public function CekDigit($attribute,$params)






$this->addError(‘Error’, $params['message']);

return false;



while in rule, i put this code >>


array('string1','cekdigit','message'=>'the code is unmatched','subject'),


thanks for the next solution :D

Ups, i forget something.

I have tried that code above, and filled the string1 with 23xxxxxxx.

then i got an error, which is CException : Property model.23 is not defined.

Could you help me?

Your exception is because you’re using $this to access a local variable. I assume you mean to just say $attribute instead of $this->$attribute.