Jump to content

Simple Solution I think...


Praetorian46

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.