In $contents
, I'd like to grab everything after the pipe e.g. boss
.
$search_for = "micky.mcgurk";
$contents = "micky.mcgurk@somewebsite.com|boss";
$pattern = sprintf('/\b%s@([^|\s]+)\|/m', preg_quote($search_for));
if (preg_match_all($pattern, $contents, $matches)) {
$submitted_by = implode("\n", $matches[1]);
} else {
echo "No user found";
}