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 ? Quote 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. Quote 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? Quote 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]); Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/63900-solved-splitting-a-name/#findComment-318502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.