note 72107 deleted from ref.pcre by nlopess

From: Date: Wed, 03 Jan 2007 12:18:55 +0000
Subject: note 72107 deleted from ref.pcre by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121236@lists.php.net to get a copy of this message
Note Submitter: orijing at gmail dot com Reason: spam ---- To make sure my IPB forum (http://originxt.com -- click around and notice the clean SEO-friendly URLs) spits out only the most clean URLs, I use PCRE to check and clean every single internal link. I use the following, which I put in functions.php and is called by a preg_replace with 'ie' in the display class file. <?php function parse_queries($query,$type='a',$the_base) { global $ibforums; if(strstr(strtolower($_SERVER['SystemRoot']),'win') !== false) return $query; $query = str_replace( array('&amp;','&','=','/act-','/code-','/home/','/00/'), array('/','/','-','/','/','/','/'), strtolower(preg_replace("#/*\##","/#","/".$query."/")) ); // cut off empty values $match = "#/([\d\w_]*?)-0?/#"; while(preg_match($match,$query)) { $query = preg_replace($match,"/",$query); } // mnemonic changes $query = preg_replace( array ( "#/post/02/f-\d+/t-(\d+)/qpid-(\d+)/#", "#/post/02/f-\d+/t-(\d+)/#", "#/st/f-\d+/t-(\d+)/#", "#/post/14/f-\d+/t-(\d+)/#", "#/(post/0?8/f-\d+/t-\d+/p|editpost)-(\d+)/#", "#^.+findpost(.*?)/(pid|p)-(\d+)/#", "#/p-\d+/#", "#/post/10/f-(\d+)/#", "#/post/f-(\d+)/#", "#/msg/0?4/mid-(\d+)/#", "#/msg/0?3/msid-(\d+)/#", ), array ( "/node/$1/quote/$2/", "/node/$1/reply/", "/node/$1/", "/node/$1/addpoll/", "/posts/$2/edit/", "/posts/$3$1/", "/", "/cat/$1/poll/", "/cat/$1/new/", "/members/$1/pm/", "/messages/$1/", ), $query); $query = str_replace( array('/idx','/sf/f-','/showforum-', '/st/t-','/showtopic-','/profile/mid-','/showuser-'), array('/forums','/cat/','/cat/','/node/', '/node/','/members/','/members/'), $query ); // if guest, remove the member-only stuff (sessions, mode, view, etc) if(!$ibforums->member['id'] and strtolower($type) == 'a') { if(preg_match( "#/(usercp|forward|print|online|mod|track)/#i" ,$query)) { $query = "//"; } else $query = preg_replace(array("#/mode-\w+/#", "#/view-\w+/#"),"/",$query); } // make sure /st is second in line $query = preg_replace("#^/+(\w+/[^/]+?)/(.*?)/st-(\d+)#", "/$1/st-$3/$2",$query); $query = preg_replace( array("#/node/(\d+)/st-(\d+)#", "#/cat/(\d+)/st-(\d+)#"), array("/node/$1.$2","/cat/$1.$2"), $query ); // Take away trailing and beginning /s $query = preg_replace("#/+\##","#",$query); $query = preg_replace(array("#/+$#","#^/+#"),"",$query); return $query; } ?> Enjoy. It needs optimization, for sure, but it gets the job done on a server of pretty much unlimited resources.

« previous php.notes (#121236) next »