Regex Assistance

From: Date: Tue, 28 May 2002 01:59:38 +0000
Subject: Regex Assistance
Groups: php.general 
Request: Send a blank email to php-general+get-99420@lists.php.net to get a copy of this message
Hey All, I am just begining to learn regex functions in PHP. Anyhow I am trying to code a preg_replace function which basically cleans a URL. What I mean is say a url is index.php?page=hello&list=10&start=4 you pass that URL and say 'list' to the function (shown below) Anyhow I want that to then return index.php?page=hello&start=4 (see how the entire list reference is now gone) Here is what I have come up with so far, though I am yet to test it as I am coding this at work :) function stripUrl($url, $url_strip) { // Check that $url_strip is in the URL if(strpos($url,'?') && strpos($url, $url_strip.'=')) { // Lets clean up the url $url = preg_replace("/\?|&$url_strip=/", "", $url); } return $url; } My problem is that, how do I make the preg_replace stop when it encounters a & in the URL? If anyone could shed some light on this it would be appreciated, - Regards, Scott

« previous php.general (#99420) next »