jakebur01 Posted August 8, 2007 Share Posted August 8, 2007 I have a variable $name for example which holds two words " John Smith " . Is there any way to break this name into two variables? Example: $firstname = John $lastname = Smith ? Link to comment https://forums.phpfreaks.com/topic/63900-solved-splitting-a-name/ Share on other sites More sharing options...
akitchin Posted August 8, 2007 Share Posted August 8, 2007 $pieces = explode(' ', trim($name)); print_r($pieces); voila. Link to comment https://forums.phpfreaks.com/topic/63900-solved-splitting-a-name/#findComment-318491 Share on other sites More sharing options...
jakebur01 Posted August 8, 2007 Author Share Posted August 8, 2007 Thats awesome. How do I now make this variable active? $a->add_field('x_first_name', '$name'); all I get with this is $name rather than John. Should I use double quotes? Link to comment https://forums.phpfreaks.com/topic/63900-solved-splitting-a-name/#findComment-318498 Share on other sites More sharing options...
micah1701 Posted August 8, 2007 Share Posted August 8, 2007 $pieces = explode(' ', trim($name)); $a->add_field('x_first_name', $pieces[0]); $a->add_field('x_last_name', $pieces[1]); Link to comment https://forums.phpfreaks.com/topic/63900-solved-splitting-a-name/#findComment-318500 Share on other sites More sharing options...
jakebur01 Posted August 8, 2007 Author Share Posted August 8, 2007 thanks. Link to comment https://forums.phpfreaks.com/topic/63900-solved-splitting-a-name/#findComment-318502 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.