简体   繁体   中英

Split an email address into username, host and domain

I get an email address from the database. I need to split and collect it to protect it. There is a way, but I don't understand how to apply it fully.

For example we have an email address me@example.com

We split it down:

> me
> example
> com

and collect.

Here is an example function

@php

$split = explode('@', $email);
$first = $split[0];
$second = explode('.', $split[1])[0];
$third = explode('.', $split[1])[1];

<a href="" data-first="first" data-second="second" data-third="third">{{ $email }}</a>

@endphp

How can I properly apply the fields $first $second $third to collect the email?

why not do it in simple way?

just echo it with php code will do.

$split = explode('@', $email);
$first = $split[0];
$second = explode('.', $split[1])[0];
$third = explode('.', $split[1])[1];

<a href="" data-first="<?=$first?>" data-second="<?=$second?>" data-third="<?=$third?>">{{ $email }}</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM