0

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?

ADyson
  • 57,178
  • 14
  • 51
  • 63
chu
  • 35
  • 1
  • 12
  • When you say "apply", do you mean how to put those values into the `data-` attributes of the HTML? It's not very clear what exactly your issue is. Try to be very specific about the goal and the problem instead of using ambiguous words. Thanks,. – ADyson Oct 13 '21 at 08:43
  • @ADyson yes, that's right, sorry if something is not clear – chu Oct 13 '21 at 08:44
  • What you really want is so unclear. Please tell us what you really want. –  Oct 13 '21 at 08:44
  • @Ajay i need to put values `$first` `$second` `$third` ​​in `data-`attributes – chu Oct 13 '21 at 08:46
  • Would you like to get an email from the user by this email? If it is, you don't need to split it just use simple HTML ` – Mainul Hasan Oct 13 '21 at 08:52
  • Ok and what is stopping you from doing that exactly? Did you try anything? You clearly know how to use blade syntax because you wrote `{{ $email }}` already. So why can't you write `data-first="{{ $first }}"` etc in the same way? – ADyson Oct 13 '21 at 08:53
  • @MainulHasan I need this way to protect against spam, but I also need to receive messages on it – chu Oct 13 '21 at 08:58
  • @ADyson okay, thanks – chu Oct 13 '21 at 08:59
  • @MainulHasan Maybe then tell me which method is better to use for protection in my case – chu Oct 13 '21 at 09:00
  • P.S. I also don't think this technique will be that helpful against spam, because if someone scrapes your page for email addresses, their bot will still see the email address in full where you've put `{{ $email }}`. So they can still harvest it and send spam to it. – ADyson Oct 13 '21 at 09:07
  • @ADyson Is there some good way for my case? – chu Oct 13 '21 at 09:09
  • It's not something I have personal expertise in so I can't tell you what the latest techniques are myself, but I would expect if you [do some research, starting by clicking on this link](https://www.google.com/search?q=protect+mailto+links+from+spam) then you'll get more than enough information to help you - one thing I do know is that this is not a new problem. – ADyson Oct 13 '21 at 09:13
  • @ADyson I'm understood, thank you – chu Oct 13 '21 at 09:20

1 Answers1

0

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>
  • You can see from the original that OP is using Laravel blade syntax though...it would make sense to stick to that format, for consistency and reliability. – ADyson Oct 13 '21 at 09:05