Praetorian46 Posted December 20, 2007 Share Posted December 20, 2007 I need help stripping a few characters "0," out of a string but i don't want to it to strip it out if it is "10," or "20," or something like that.. here is the code that I am working with now... I'm kinda new to PHP so it may be a bit messy. ??? $Cust_ID = implode(",", $Cust_ID); $Job_ID = implode(",", $Job_ID); $Empl_ID = implode(",", $Empl_ID); $Class_ID = implode(",", $Class_ID); if($Cust_ID!="" AND $Cust_ID!="0") $Message = 'Cust_ID: ' . $Cust_ID; if($Job_ID!="" AND $Job_ID!="0") $Message .= '<br> Job_ID: ' . $Job_ID; if($Empl_ID!="" AND $Empl_ID!="0") $Message .= '<br> Empl_ID: ' . $Empl_ID; if($Class_ID!="" AND $Class_ID!="0") $Message .= '<br> Class_ID: ' . $Class_ID; Die($Message); That outputs this... Cust_ID: 0,3,4,5,1,6,7,8,9,10,11,16,15,14,17,12,13,2 Job_ID: 0,3,1,2 Empl_ID: 0,2,1 Class_ID: 0,1,2 I'm getting the arrays by having a bunch of values selected in a MULTIPLE SELECT box. If the user selects the ID "0" I want that to be ignored since ID "0" is the word "ANY" and will be left out of the query I'm going to run with this data... I hope I provided enough info for you to help me out. Thank you, -Cody Quote Link to comment Share on other sites More sharing options...
revraz Posted December 20, 2007 Share Posted December 20, 2007 How about not allow 0 to display as a choice? Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 use str_replace to replace any ,0 with an empty string '' Then check if the very first character of the string is 0 and if so remove it and the subsequent comma. Or you could loop through the array before you implode it and unset any values == 0 Quote Link to comment Share on other sites More sharing options...
Praetorian46 Posted December 20, 2007 Author Share Posted December 20, 2007 Well because if they click anywhere in the box it selects something... So in order for them to unselect it they would have to {Crtl} Click on what ever they clicked on. These guys are idiots that are going to be using this script. It's easier to just exclude the 0 that is selected.. At least I think it is. Maybe the issue I am having isn't as easy as I thought. Quote Link to comment Share on other sites More sharing options...
Praetorian46 Posted December 20, 2007 Author Share Posted December 20, 2007 use str_replace to replace any ,0 with an empty string '' Then check if the very first character of the string is 0 and if so remove it and the subsequent comma. Or you could loop through the array before you implode it and unset any values == 0 The looping through the array seems to be the easiest way to go about this... I don't know why I didn't think of that :-\ I knew it was something simple I was just over looking. Thanks a bunch Jesirose! Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 No problem. And always assume your users are both complete idiots, and amazing hackers. Check EVERYTHING for ANY possible errors and test it out. 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.