whiteboikyle Posted August 10, 2011 Share Posted August 10, 2011 $name = 'Kyle Cribbs'; how to make this into an array like $array[0] = Kyle; $array[1] = Cribbs; I know there is a php function that will do this but dont know what it is -.- haha Link to comment https://forums.phpfreaks.com/topic/244459-splitting-a-variable/ Share on other sites More sharing options...
AyKay47 Posted August 10, 2011 Share Posted August 10, 2011 $name = 'Kyle Cribbs'; $explode = explode(" ",$name); Link to comment https://forums.phpfreaks.com/topic/244459-splitting-a-variable/#findComment-1255629 Share on other sites More sharing options...
whiteboikyle Posted August 10, 2011 Author Share Posted August 10, 2011 THANKS! another question this doesnt really regard that, well kinda, but lets say i exploded it like so $fullName = 'kyle cribbs' $name = explode(' ', $fullName); how would i do a 'like' SQL using an array? like this? SELECT * FROM `users` WHERE `name` LIKE '%$name%' Link to comment https://forums.phpfreaks.com/topic/244459-splitting-a-variable/#findComment-1255631 Share on other sites More sharing options...
MasterACE14 Posted August 11, 2011 Share Posted August 11, 2011 THANKS! another question this doesnt really regard that, well kinda, but lets say i exploded it like so $fullName = 'kyle cribbs' $name = explode(' ', $fullName); how would i do a 'like' SQL using an array? like this? SELECT * FROM `users` WHERE `name` LIKE '%$name%' $fullName = 'kyle cribbs' $name = explode(' ', $fullName); $sql = "SELECT * FROM `users` WHERE `name` LIKE '%".$name[0]."%'"; // $name[0] = kyle , $name[1] = cribbs Link to comment https://forums.phpfreaks.com/topic/244459-splitting-a-variable/#findComment-1255636 Share on other sites More sharing options...
whiteboikyle Posted August 11, 2011 Author Share Posted August 11, 2011 What if its more then 2 arrays Link to comment https://forums.phpfreaks.com/topic/244459-splitting-a-variable/#findComment-1255657 Share on other sites More sharing options...
jcbones Posted August 11, 2011 Share Posted August 11, 2011 Then: $fullName = 'kyle cribbs' $name = explode(' ', $fullName); foreach($name as $value) { $search[] = "`name` LIKE '%$value%'"; } $sql = "SELECT * FROM `users` WHERE " . implode(' OR ', $search); //name LIKE '%kyle%' OR name LIKE '%cribbs%' Link to comment https://forums.phpfreaks.com/topic/244459-splitting-a-variable/#findComment-1255671 Share on other sites More sharing options...
AyKay47 Posted August 11, 2011 Share Posted August 11, 2011 Then: $fullName = 'kyle cribbs' $name = explode(' ', $fullName); foreach($name as $value) { $search[] = "`name` LIKE '%$value%'"; } $sql = "SELECT * FROM `users` WHERE " . implode(' OR ', $search); //name LIKE '%kyle%' OR name LIKE '%cribbs%' good solution.. Link to comment https://forums.phpfreaks.com/topic/244459-splitting-a-variable/#findComment-1255798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.