I'm writing a function that should retrieve all occurrences that I pass. I'm italian so I think that I could be more clear with an example. I would check if my phrase contains some fruits.
Ok, so lets see my php code:
$pattern='<apple|orange|pear|lemon|Goji berry>i';
$phrase="I will buy an apple to do an applepie!";
preg_match_all($pattern,$phrase,$match);
the result will be an array with "apple" and "applepie".
How can I search only exact occurency? Reading the manual I found: http://php.net/manual/en/regexp.reference.anchors.php
I try to use \A
, \Z
, ^
and $
but no one seems to work correctly in my case!
Someone can help me?
EDIT: After the @cris85 's answer I try to improve my question ... My really pattern contains over 200 occorrency and the phrase is over 10000 caracters so the real case is too large to insert here.
After some trials I found an error on the occurrency "microsoft exchange"! There is some special caracters that I must escape? At the moment I escape "+" "-" "." "?" "$" and "*".