1

I want to transfer the value of my array into my variables. My array contain 2 value, [0]Firstname [1]Lastname. i want to store it to

$fname = array[0] //firstname
$lname = array[1] //lastname 

here's my code:

<?php
$str  = "[email protected]";
$str = str_replace('@email.com', '', $str);
print_r ((explode(".",$str)), true);
?>  
1
  • 1
    What's the problem? You get the first name and last name from the email address. What do you want to do next? Assign the values from array into scalar variables? You already do it at the beginning. Commented Aug 8, 2014 at 8:37

4 Answers 4

1

If I understood correctly, this is what you seek:

list( $fname, $lname ) = explode( '.', $str );
Sign up to request clarification or add additional context in comments.

Comments

0

Just try with:

list($name) = explode('@', $str);
list($fname, $lname) = explode('.', $name);

Comments

0

Yet another option:

$str = "[email protected]";

preg_match('~(?P<fname>.+?)\.(?P<lname>.+?)@(?P<host>.+)$~', $str, $matches);
extract($matches);

var_dump($fname);
var_dump($lname);
var_dump($host);

Comments

0
$str  = "[email protected]";
$str = str_replace('@email.com', '', $str);
$str = explode(".",$str);

$fname = $str[0] //firstname
$lname = $str[1] //lastname 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.