On my website I have a list of news available at /news/ which displays all news. I allow news to be filtered based on subject by adding categories to the URL like: /news/sports or multiple categories /news/sports+politics+crime
Within my application I explode the URL on the + and build an array which I use to grab the correct news items. In addition to grabbing the items, I also print "Tags" onto the page, with an "X" to remove the given category. So if you went to /news/sports+politics+crime then above the list of News I have printed Sports[X] Politics[X] Crime[X]
What I want to do, is like the [X] to the same URL MINUS the category that is being removed. So the href tag of the crime [X] would be /news/sports+politics but the href tag of sports would be /news/politics+crime
What is the best way to do this?
While generating the page I am looping thru my array of categories like so:
foreach ($category as $cat) {
echo $cat . '<a href="/news/">[X]</a>';
}
What is the best way to print the link without the category being removed? I was thinking I could somehow flatten the array into a plain old string, and find/replace the given item ex +crime and then turn that back into a URL. Any ideas?