Title: [Plugin: add-rel-lightbox] Warning preg_replace
Last modified: August 20, 2016

---

# [Plugin: add-rel-lightbox] Warning preg_replace

 *  Resolved [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/)
 * I get this error when searching with relevanssi (a search that will return result
   with images):
 * Warning: preg_replace() [function.preg-replace]: Unknown modifier ‘C’ in \wp-
   content\plugins\add-rel-lightbox\add_rel_lightbox.php on line 61
 * Any idea?
 * [http://wordpress.org/extend/plugins/add-rel-lightbox/](http://wordpress.org/extend/plugins/add-rel-lightbox/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Thread Starter [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/#post-2790733)
 * The strange thing is I get this on some searches but not all…
 *  Thread Starter [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/#post-2790734)
 * I uinderstoofd then it has to do with what it finds in my results and how it 
   transforms it.
 * So I removed the reference to the tithe in the lines:
 *     ```
       // $pattern = "/<a href='(.*?).(jpg|jpeg|png|gif|bmp|ico|svg)' title='" . $attachment->post_title . "'><img(.*?)class=\"attachment-thumbnail\"(.*?)\/><\/a>/i";
       ```
   
 *  for
 *     ```
       $pattern = "/<a href='(.*?).(jpg|jpeg|png|gif|bmp|ico|svg)'><img(.*?)class=\"attachment-thumbnail\"(.*?)\/><\/a>/i";
       ```
   
 * And also
 *     ```
       //$replace = '<a href="${1}.${2}" rel="prettyPhoto[post-' . $id . ']" title="' . $caption . '"><img${3}class="attachment-thumbnail"${4}/></a>';
       ```
   
 *  for
 *     ```
       $replace = '<a href="${1}.${2}" rel="prettyPhoto[post-' . $id . ']"><img${3}class="attachment-thumbnail"${4}/></a>';
       ```
   
 * If someone knows better, I’d do!
 *  Plugin Author [DefProc](https://wordpress.org/support/users/defproc/)
 * (@defproc)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/#post-2790969)
 * Hmmm… The most likely thing is the title content is breaking the regexes. Version
   0.4 doesn’t use regexes to do the page parsing, so it might be more robust.
 * If you send a copy of the page content that causes the error, I’ll take a look
   and see what’s causing the problem. You can email it to me at (contact [at] def-
   proc.co.uk) if you’d rather not post it publically here.
 *  Thread Starter [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/#post-2790985)
 * Hi DefProc,
    It was on a prod site here [http://www.morija.co.ls/morija/?s=hat&post_type=objects](http://www.morija.co.ls/morija/?s=hat&post_type=objects)(
   demo/demo) I have just restored the unmodified file of the plugin so you can 
   seee the error. Please tell me what you think! Thanks, Agnes
 *  Thread Starter [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/#post-2790986)
 * When the error is on on the page above, the re is no excerpt for the 1st item“
   basotho hat”
    On my local version with a modified version of the plugin where
   I dont get the error, I get the excerpt and that is:
 * > _Basotho Hat
   >  It is a beautiful hat that is made from various types of grasses.
   > Basotho wore these ha…
 * So it seems something in this text is causing the replace function to fail… Is
   it that the last word (“hat”) is cut?
 *  Plugin Author [DefProc](https://wordpress.org/support/users/defproc/)
 * (@defproc)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/#post-2790987)
 * Yep, from a quick look, my best guess is that it’s the lack of the precision 
   in the gallery regex. I can’t be sure without seeing the page content without
   add-rel-lightbox activated, to see if it has changed anything, but the gallery
   regex *shouldn’t* match for this page.
 * I think that instead of matching:
 * `<a […]><img […]></a>`
 * it’s actually matching:
 *     ```
       <a […]></a>
       […]
       <img […]>
       […]
       <a […]></a>
       ```
   
 * and because the extra content has some unescaped `/`s in it, it’s breaking the`/(
   pattern)/i` and adding a `/c` inside the pattern. This is an example of why regexes
   are bad for parsing HTML and why the plugin hasn’t reached version 1 yet.
 * I’ve changed to DOM parsing in version 0.4, so the see if an upgrade sorts it
   out.
 *  Thread Starter [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * (@agneslesagegmailcom)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/#post-2790988)
 * I can’t really follow you that far!
    But I’ll now revert the version with my 
   above fix (and by the way that lets you see the page without that mistake) It
   is still here: [http://www.morija.co.ls/morija/?s=hat&post_type=objects](http://www.morija.co.ls/morija/?s=hat&post_type=objects)
   The stragne thing is, the same code for the “zoom” where the rel lightbox is 
   used works also here: [http://www.morija.co.ls/morija/museum/collections/](http://www.morija.co.ls/morija/museum/collections/)
   I dont get why with the serach function (I guess because of highlighting the 
   search terms) it does not sometimes… This is using Relevanssi by the way. Also,
   I am passing a number of HTML colde in the zoom link, may be then it gets wild…
   A1nyhow.. the fox does for me. Thanks! Agnes

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘[Plugin: add-rel-lightbox] Warning preg_replace’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/add-rel-lightbox.svg)
 * [add-rel-lightbox](https://wordpress.org/plugins/add-rel-lightbox/)
 * [Support Threads](https://wordpress.org/support/plugin/add-rel-lightbox/)
 * [Active Topics](https://wordpress.org/support/plugin/add-rel-lightbox/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/add-rel-lightbox/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/add-rel-lightbox/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Agnes](https://wordpress.org/support/users/agneslesagegmailcom/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-add-rel-lightbox-warning-preg_replace/#post-2790988)
 * Status: resolved