Removing bits and pieces from a url

i have a script that tells a page to display things depending on whats in a value thats gotten from the location of the page

the location looks something like

i want to add links so people can select which ids they want to view and which ones they dont but im not sure how to safely modify the location

how could i remove something say in the middle of that?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That's not too hard to do with PHP, using arrays and conditional statements. =) Try something like the following, you can use it directly or make a function out of it for repeated use.

$value = explode(",", $value);
for ($i = 0; $i < count($value); $i++) {
    $bits = explode(".", $value[$i]);

    if ($bits[0] != $remove) {
        $newvalue .= $value[$i] . ",";

$newvalue = preg_replace("/,$/", "", $newvalue);

Since php puts everything into variables by default, $value would actually be $blah in accordance with your example above. What this is doing, is splitting the value by the ,'s and looping through to see if it's the one you don't want (designated by $remove, edit that as you want), and putting the rest in a new comma delimited value.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tsmittAuthor Commented:
hmm whats the point of the $bits variable?
Sorry, I cut and pasted the code piece from one of my scripts where I do something very similar to what I believe you're describing. I merely forgot to remove that part. You could do:

1: $value = explode(",", $value);
2: for ($i = 0; $i < count($value); $i++) {
3:        if (!preg_match("/$remove/", $value[$i])) {
4:            $newvalue .= $value[$i] . ",";
5:        }
6: }
8: $newvalue = preg_replace("/,$/", "", $newvalue);

Which probably makes more sense for you. Line 1 is where you split the value from the url into an array, seperated by , or whatever else you may want to use. The second line starts a loop to go through each value in the array that was created, and 3-5 checks to make sure it's not a value you want to remove before creating the new value. Finally, line 8 removes any trailing commas you may have to clean up the look.
tsmittAuthor Commented:
great that worked! thanx
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.