I have a string and I want to extract out some information for it.
The string could be like this
$string = "Followers: abc.com. ID by: xyz@gmail.com. More info: all the rest of information goes here. All other goes everywhere else."
the $string sometimes just have
$string = "ID by: xyz@gmail.com."
or
$string = "Followers: abc.com."
or any other combo. I am just trying to see if there is ID by there and get that out.
What would be the best way to achieve this
Use a regular expression with
preg_matchto find the ID.The ID (email address) will be in
$matches[1]. The pattern matches “ID by: “, captures the email address, and finally requires a period + space or end of string.