...

View Full Version : problems with preg_match()



surreal5335
12-05-2010, 10:36 AM
I am having trouble getting my preg_match() to work properly.

Here is the code I have:



define('EBOOK_ROOT', '//millionaire/ebooks.php/');
define('DS', '/');

$url = $_SERVER['REQUEST_URI'];

if(preg_match(EBOOK_ROOT, $url))
{
$url = str_replace(EBOOK_ROOT.DS,'',$url);
}


I have been trying to find a good documentation on use of regular expressions in PHP, but havnt really found any

Thanks a lot for the help

Lamped
12-05-2010, 11:34 AM
So, basically, the RegEx starts with an "special character". In most cases, this is a "/" like yours is. The RegEx ends with it too, and then has an "option" section (ixs etc). An empty RegEx that's case-insensitive would look like: "//i". Now, being a special character, if it appears at any point in the main part of the RegEx, you *MUST* escape it using "\".

To match "/":
"/\//"

To match "/millionaire/ebooks.php":
"/\/millionaire\/ebooks.php/"

Or you can change the special character:
"@/millionaire/ebooks.php@"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum