SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Preg_match error: unknown modifier "-"

    Hi,

    I'm getting an error in a regular expression, which is built like this:

    PHP Code:
    preg_match ('/(<.*) ' $attribute '=(\'|")' $val '(\'|".*>)/'$string
    The resulting pattern is this in one case:

    Code:
    /(<.*) type=('|")application/x-shockwave-flash('|".*>)/
    This gives me the error:

    Code:
    Warning:  preg_match() [function.preg-match]: Unknown modifier '-'
    I don't really understand the error. Aren't modifiers supposed to be the characters at the end of a pattern? (/i, /x etc.)
    And secondly, if my value happens to contain a "-", I still need the regular expression to work.

    I've tried preg_quote, but that doesn't do anything to the "-".

    Does anyone know a solution to this problem?

    Thanks in advance!

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ooops, I misread.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ize View Post
    I don't really understand the error. Aren't modifiers supposed to be the characters at the end of a pattern? (/i, /x etc.)
    That is correct, but in your pattern you have an un-escaped forward slash.

    The first character after it in this case is a "-", which is an unknown modifier.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Try applying preg_quote to the dynamic elements to your pattern, which should stop these elements invalidating it.

    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Guru Ize's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bhanson View Post
    That is correct, but in your pattern you have an un-escaped forward slash.

    The first character after it in this case is a "-", which is an unknown modifier.
    Of course!
    Thanks so much, I totally overlooked that.

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SilverBulletUK View Post
    Try applying preg_quote to the dynamic elements to your pattern, which should stop these elements invalidating it.

    Function noted
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this
    PHP Code:
    preg_match ('/(<.*) ' $attribute '=(\'|")' str_replace('-''\-'$val) . '(\'|".*>)/'$string); 
    SetCronJob is a free cron jobs service.
    The easiest way to set cron job.


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
  •