Results 1 to 4 of 4

Thread: PCRE syntax as it relates to wwws and https

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default PCRE syntax as it relates to wwws and https

    Hi,

    I found a script that uses wwws and https as part of a pattern match, but https and wwws is not listed anywhere in the list of terms available for use in the syntax page listed at php.net or pcre.org. What other terms are useable in pcre for pattern matching that is not listed on the syntax page? How is https and wwws defined and used? Why is https used as opposed to http? From what I can see the pcre engine should not be able to recognize any urls by using https, but it does.

    the following is an example, not that it is really needed.
    PHP Code:
    $text=preg_replace('/(https?:\\/\\/[-_.\\/\w\d!&%#?+\\,\\\\\'=:;@~]+)/i''<a href="$1">$1</a>'$text); 
    Last edited by james438; 09-28-2008 at 12:57 AM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It does, because it's got 'https?' -- that is to say, the string 'http' followed optionally by the character 's'.

    HTTPS is 'secure HTTP' -- basically HTTP over a SSL (Secure Sockets Layer) connection, which provides transparent encryption.

    There's no such thing as WWWS, unless you mean the American 'rhythmic oldies' radio station.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Quote Originally Posted by Twey View Post
    There's no such thing as WWWS, unless you mean the American 'rhythmic oldies' radio station.
    hehe, no I didn't mean that

    The wwws must be an error in my pcre command. I didn't know that the ? could be used within single quotes like that. I have always used it only as a quantifier as located outside of a character class or subpattern or in conjunction with a few other things like .*? or ?: etc. It looks like if I wanted to have more than one character optional I would enclose it in round brackets like "htt(ps)?".

    Thanks for pointing me back in the right direction
    Last edited by james438; 09-27-2008 at 01:24 AM.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you want the grouping effect of the brackets without actually capturing, you can write htt(?:ps)?, although this is purely a convenience and offers no performance benefit.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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