EchoFool Posted July 10, 2008 Share Posted July 10, 2008 I have a value which carries to bits of infomation seperated by | symbol. But I do not know how to split them into two different variables. <?php $ID = 'Country|23'; $IDType = explode('|', $ID, -1); $IDType[0] = $Type; $IDType[1] = $TypeID; ?> What im trying to get is $Type = Country; $TypeID = 23; But it is not working, what am i doing wrong ? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 10, 2008 Share Posted July 10, 2008 you want this <?php $ID = 'Country|'.23; $IDType = explode('|', $ID,); $Type = $IDType[0]; $TypeID = $IDType[1]; ?> i don't think this will work $IDType[0] = $Type; it should try to set $IDType[0] to $Type instead. Scott. Quote Link to comment Share on other sites More sharing options...
gijew Posted July 10, 2008 Share Posted July 10, 2008 You have it backwords a bit. Try this. <?php $ID = 'Country|'.23; $IDType = explode('|', $ID, -1); $Type = $IDType[0]; $TypeID = $ID Type[1]; ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 10, 2008 Share Posted July 10, 2008 <?php $ID = 'Country|23'; list($Type,$TypeID) = explode('|', $ID, 2); ?> Quote Link to comment Share on other sites More sharing options...
EchoFool Posted July 10, 2008 Author Share Posted July 10, 2008 Thankyou for your reply! I am getting this how ever now as an error: Notice: Undefined offset: 1 on line 57 <?php $IDType = explode('|', $ID, -1); $Type = $IDType[0]; $ID = $IDType[1]; //this line ?> Quote Link to comment Share on other sites More sharing options...
ratcateme Posted July 10, 2008 Share Posted July 10, 2008 why do you have the -1 in the explode remove it then try Scott. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted July 10, 2008 Author Share Posted July 10, 2008 Scott, I don't know I saw it in the php site so presumed it was needed. But it is fixed now i have removed it. So thankyou for that! Quote Link to comment Share on other sites More sharing options...
Barand Posted July 11, 2008 Share Posted July 11, 2008 <?php $ID = 'Country|23'; list($Type,$TypeID) = explode('|', $ID, 2); ?> It happens all the time - the best solution is totally ignored. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 11, 2008 Share Posted July 11, 2008 <?php $ID = 'Country|23'; list($Type,$TypeID) = explode('|', $ID, 2); ?> It happens all the time - the best solution is totally ignored. thanks for the props Quote Link to comment 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.