Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts

    problems with preg_match()

    I am having trouble getting my preg_match() to work properly.

    Here is the code I have:

    Code:
    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

  • #2
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    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@"
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •