I'm not entirely sure how to do this, but maybe someone here does. I have a string like this: $string = "index.php?id=5&value=7&page=4&customer=1"; I want to remove the substring "page=4". The thing is, the page=4 value isn't guaranteed to be in that place, nor is it guaranteed to equal 4 (may equal multiple digits). I'm terrible with strings. Has anyone done something like this before? Thanks.
Hm, I would do it by exploding the string on the question mark and the ampersand, and then reconstruct it without the page part.
If you are sure the substring will always start with "page=", you could use regular expressions to take it out.
Using regex (strips out the leading "&" char too, if exists): $string = preg_replace('/&?page=\d+/si','',$string); PHP: