chu
chu

Reputation: 35

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 [email protected]

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?

Upvotes: 0

Views: 883

Answers (1)

user8486381
user8486381

Reputation:

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>

Upvotes: 0

Related Questions