note 72643 deleted from function.preg-replace by colder
| From: | colder@php.net | Date: | Sat, 27 Jan 2007 16:40:26 +0000 |
| Subject: | note 72643 deleted from function.preg-replace by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122269@lists.php.net to get a copy of this message | ||
Note Submitter: thecolor
Reason: bad code
----
OK, so I figured out how to remove the url at the beginning and end easier, but then found I needed
additional checks due to slight changes in the way the urchin tags were written at times. :(
So, I brought it down to this:
<?php
$siterefname = $_SERVER['HTTP_REFERER'];
// remove everything to the left of the urchin code "utmcsr%3D" and a few other
possibilities (or everything to the left of it)
$siterefname = preg_replace('/(.*)(.*?)utmcsr%3D/i', '', $siterefname);
$siterefname = preg_replace('/(.*)(.*?)utmcsr=/i', '', $siterefname);
$siterefname = preg_replace('/(.*)(.*?)utm_source%3D/i', '', $siterefname);
$siterefname = preg_replace('/(.*)(.*?)utm_source=/i', '', $siterefname);
//remove the code after the desired urchin text (or everything to the right of
"%7Cutmccn") and a few other possibilities
$siterefname = preg_replace('/%7Cutmccn(.*?)(.*)/i', '', $siterefname);
$siterefname = preg_replace('/|Cutmccn(.*?)(.*)/i', '', $siterefname);
$siterefname = preg_replace('/&utm_medium=(.*?)(.*)/i', '', $siterefname);
$siterefname = preg_replace('/&__utmv(.*?)(.*)/i', '', $siterefname);
//remove the extra characters and replace them with cleaner looking chars (in this case the plus
char "+")
$siterefname = str_replace("%7C","+",$siterefname);
$siterefname = str_replace("%3D","+",$siterefname);
$siterefname = str_replace("%2B","+",$siterefname);
?>
I was told that this value "(.*?)" is either, not necessary or the "?" mark is
not, and that I can get this down to a single line, although I'm not sure how to get it down to
one line yet. Any suggestions. :)