Results 1 to 6 of 6

Thread: Problem with stars in preg_replace conversion

  1. #1
    Join Date
    Jan 2016
    Posts
    23
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Problem with stars in preg_replace conversion

    Need help with this
    PHP Code:
    eregi_replace("title=\"([^\\[]*)\">link</a>\\]\\]","]",$text); 
    I've been using stars to convert to preg_replace but there is already a star present and it's giving more errors. How do I fix it?

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I'm guessing that you're referring to a conflicting delimiter? If you regex has an asterisk (star) in it already, you can just use another character;
    Code:
    preg_replace("#title=\"([^\\[]*)\">link</a>\\]\\]#i","]",$text);
    This one uses '#' as the delimiter.

    Is that what you mean? Does that help?
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. The Following User Says Thank You to Beverleyh For This Useful Post:

    bojangles (01-18-2016)

  4. #3
    Join Date
    Jan 2016
    Posts
    23
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default

    Thanks. That helps a bunch. Your code looks a little different to mine with the i at the end of the line. May I ask what that is for? Will it make a difference if I don't use it?

  5. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You original code used eregi_replace, which is for case-insensitivity, so the "i" after the # delimiter in the updated preg_replace function does the same thing - it makes the regex case-insensitive.

    If case-insensitivity was in effect in the earlier version of your script, it would be best to keep it that way in the update to avoid any complications/incompatibilities with whatever text is being replaced.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  6. The Following User Says Thank You to Beverleyh For This Useful Post:

    bojangles (01-18-2016)

  7. #5
    Join Date
    Jan 2016
    Posts
    23
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default

    Okay, I will change my code to match your example.

    Thanks again for your help. I will probably need more help soon so I will return.

  8. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    No problem. Come back any time
    Last edited by Beverleyh; 01-18-2016 at 02:47 PM. Reason: typo
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  9. The Following User Says Thank You to Beverleyh For This Useful Post:

    bojangles (01-18-2016)

Similar Threads

  1. Replies: 0
    Last Post: 09-28-2011, 06:42 AM
  2. voting script with stars
    By chechu in forum PHP
    Replies: 1
    Last Post: 11-24-2009, 04:25 AM
  3. Date Conversion Problem
    By devil_vin in forum PHP
    Replies: 4
    Last Post: 10-09-2007, 06:15 PM
  4. Direction of stars - any help appreciated
    By lucretius in forum JavaScript
    Replies: 5
    Last Post: 07-15-2007, 05:27 PM
  5. Stars script
    By Finger Tips in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 12-28-2005, 06:23 AM

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
  •