This article mainly introduces how to use PHP to extract the username of an email address.
In our daily PHP learning process, extracting a certain piece of content from a string is a very common knowledge point, and everyone must be very familiar with it.
For novices, it is easy to learn as long as they master the relevant functions.
Recommended reference PHP video tutorial: "PHP Tutorial"
Let's use a simple example to introduce how to extract the username of an email in PHP.
The code example is as follows:
<?php $mailid = 'rayy@example.com'; $user = strstr($mailid, '@', true); echo $user."\n";
Here we are getting the user name from the email address "rayy@example.com", that is, extracting the string before the @ symbol.
The results of accessing through the browser are as follows:
#The strstr function means to find the first occurrence of a string, that is, the strstr function searches for a string in another string appears for the first time in . The return value is part of the returned string or FALSE if the needle is not found.
Then we can also express it through a simple flow chart:
This article is about the specific method of extracting the user name of the email address with PHP The introduction is very simple and easy to understand. I hope it will be helpful to novice friends!
The above is the detailed content of How to extract username of email address in php? (code example). For more information, please follow other related articles on the PHP Chinese website!