RE: [PHP] Regex Assistance
| From: | Martin Towell | Date: | Tue, 28 May 2002 02:12:48 +0000 |
| Subject: | RE: [PHP] Regex Assistance | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-99421@lists.php.net to get a copy of this message | ||
this is what I use to get rid of "line" from the url
$qs = ereg_replace("&$", "", ereg_replace("line=[^&]*&?",
"",
$QUERY_STRING));
HTH
MArtin
-----Original Message-----
From: Scott Reismanis [mailto:areisman@bigpond.net.au]
Sent: Tuesday, May 28, 2002 12:00 PM
To: php-general@lists.php.net
Subject: [PHP] Regex Assistance
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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php