private function createContact($contactInfo) { $c = new Contact(); $c->setAdresse($contactInfo); $c->setFirstName('to complet'); $c->setLastName('to complet'); $c->setComment($contactInfo); $pattern_email = '/[a-z0-9_\\-\\+]+@[a-z0-9\\-]+\\.([a-z]{2,3})(?:\\.[a-z]{2})?/i'; preg_match_all($pattern_email, $contactInfo, $matches); if (isset($matches[0]) && isset($matches[0][0])) { if (filter_var($matches[0][0], FILTER_VALIDATE_EMAIL)) { $c->setEmail($matches[0][0]); } } $pattern_phone = '/\\b\\d{2,6}[-. ]?\\d{2,6}[-. ]?\\d{2,5}([-. ]?\\d{2,5})*([-. ]?\\d{2,5})*\\b/'; preg_match_all($pattern_phone, $contactInfo, $matches); if (isset($matches[0]) && isset($matches[0][0])) { $c->setTelephone($matches[0][0]); } $this->em->persist($c); $this->em->flush(); return $c; }