I have an email
field in my database. Here I am getting it in blade
page
<h3>Email: {{ $email }}</h3>
How can I pull off the value of this field so that I can edit it, or split it like this
<span data-first="me" data-second="example" data-third="com"></span>
Where data
is my field $email
Example
@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
CodePudding user response:
Assuming you want to split [email protected]
into three separate fields:
=> john
=> example
=> com
You can do the following using the PHP's explode function():
$split = explode('@', $email); // ['john', 'example.com']
$first = $split[0]; // 'john'
$second = explode('.', $split[1])[0]; // 'example'
$third = explode('.', $split[1])[1]; // 'com'
I hope I got your question right, if not, let me know.