I have a simple regular expression for finding email addresses in a text, but even though I don’t see an error, it doesn’t work.
$addr=array();
$t='Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean fermentum risus id tortor. Morbi leo mi, nonummy eget tristique non, rhoncus non leo. Donec quis nibh at felis congue commodo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos aaa@bbb.com. Aliquam ccc@ddd.net ornare wisi eu metus.';
if(preg_match_all('~[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}~',$t,$addr, PREG_SET_ORDER)){
echo 'found';
}
I have also tried this version I found, but it didn’t work either:
if(preg_match_all('/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/',$t,$addr, PREG_SET_ORDER)){
You are matching emails that are all uppercase. You need to either do
[A-Za-z], or set the case insensitive flag onpreg_match