note 72643 added to function.preg-replace
| From: | thecolor at osu1 dot php dot net | Date: | Sat, 27 Jan 2007 15:52:06 +0000 |
| Subject: | note 72643 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122266@lists.php.net to get a copy of this message | ||
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. :)
----
Server IP: 216.194.113.175
Probable Submitter: 24.17.235.127
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/72643
Del: integrated -- https://master.php.net/note/delete/72643/integrated
Del: useless -- https://master.php.net/note/delete/72643/useless
Del: bad code -- https://master.php.net/note/delete/72643/bad+code
Del: spam -- https://master.php.net/note/delete/72643/spam
Del: non-english -- https://master.php.net/note/delete/72643/non-english
Del: in docs -- https://master.php.net/note/delete/72643/in+docs
Del: other reasons-- https://master.php.net/note/delete/72643
Reject -- https://master.php.net/note/reject/72643
Search -- https://master.php.net/manage/user-notes.php