Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2015
    Location
    United Kingdom
    Posts
    30
    Plugin Contributions
    0

    Default preg_match(): Unknown modifier '0' ???

    Hello,

    Is there any really generous PHP gurus out there who might be able to help me with something. I have been informed by my hosting company that my newly launched and updated website is causing a lot of errors. The error reads as follow:

    [28-May-2015 12:41:16 Europe/London] PHP Warning: preg_match(): Unknown modifier '0' in /home/anglersc/public_html/includes/modules/additional_images.php on line 47

    All of the errors generated seem to be related to this and I have gone into the code to try and identify this Unknown Modifier '0' but firstly I can't see a '0' on line 47 and secondly I don't really have enough php experience to see what else in the code could be causing this problem. My 'Additional_images.php' code is written below:


    Code:
    <?php
    /**
     * additional_images module
     *
     * Prepares list of additional product images to be displayed in template
     *
     * @package templateSystem
     * @copyright Copyright 2003-2011 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: additional_images.php 18697 2011-05-04 14:35:20Z wilt $
     */
    if (!defined('IS_ADMIN_FLAG')) {
      die('Illegal Access');
    }
    if (!defined('IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE')) define('IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE','Yes');
    $images_array = array();
    
    // do not check for additional images when turned off
    if ($products_image != '' && $flag_show_product_info_additional_images != 0) {
      // prepare image name
      $products_image_extension = substr($products_image, strrpos($products_image, '.'));
      $products_image_base = str_replace($products_image_extension, '', $products_image);
    
      // if in a subdirectory
      if (strrpos($products_image, '/')) {
        $products_image_match = substr($products_image, strrpos($products_image, '/')+1);
        //echo 'TEST 1: I match ' . $products_image_match . ' - ' . $file . ' -  base ' . $products_image_base . '<br>';
        $products_image_match = str_replace($products_image_extension, '', $products_image_match) . '_';
        $products_image_base = $products_image_match;
      }
    
      $products_image_directory = str_replace($products_image, '', substr($products_image, strrpos($products_image, '/')));
      if ($products_image_directory != '') {
        $products_image_directory = DIR_WS_IMAGES . str_replace($products_image_directory, '', $products_image) . "/";
      } else {
        $products_image_directory = DIR_WS_IMAGES;
      }
    
      // Check for additional matching images
      $file_extension = $products_image_extension;
      $products_image_match_array = array();
      if ($dir = @dir($products_image_directory)) {
        while ($file = $dir->read()) {
          if (!is_dir($products_image_directory . $file)) {
            if (substr($file, strrpos($file, '.')) == $file_extension) {
              if(preg_match('/\Q' . $products_image_base . '\E/i', $file) == 1) {
                if ($file != $products_image) {
                  if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {
                    //  echo 'I AM A MATCH ' . $file . '<br>';
                    $images_array[] = $file;
                  } else {
                    //  echo 'I AM NOT A MATCH ' . $file . '<br>';
                  }
                }
              }
            }
          }
        }
        if (sizeof($images_array)) {
          sort($images_array);
        }
        $dir->close();
      }
    }
    
    // Build output based on images found
    $num_images = sizeof($images_array);
    $list_box_contents = '';
    $title = '';
    
    if ($num_images) {
      $row = 0;
      $col = 0;
      if ($num_images < IMAGES_AUTO_ADDED || IMAGES_AUTO_ADDED == 0 ) {
        $col_width = floor(100/$num_images);
      } else {
        $col_width = floor(100/IMAGES_AUTO_ADDED);
      }
    
      for ($i=0, $n=$num_images; $i<$n; $i++) {
        $file = $images_array[$i];
        $products_image_large = str_replace(DIR_WS_IMAGES, DIR_WS_IMAGES . 'large/', $products_image_directory) . str_replace($products_image_extension, '', $file) . IMAGE_SUFFIX_LARGE . $products_image_extension;
        $flag_has_large = file_exists($products_image_large);
        $products_image_large = ($flag_has_large ? $products_image_large : $products_image_directory . $file);
        $flag_display_large = (IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE == 'Yes' || $flag_has_large);
        $base_image = $products_image_directory . $file;
        $thumb_slashes = zen_image(addslashes($base_image), addslashes($products_name), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
        $thumb_regular = zen_image($base_image, $products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
        $large_link = zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large);
    
        // Link Preparation:
        $script_link = '<script language="javascript" type="text/javascript"><!--' . "\n" . 'document.write(\'' . ($flag_display_large ? '<a href="javascript:popupWindow(\\\'' . str_replace($products_image_large, urlencode(addslashes($products_image_large)), $large_link) . '\\\')">' . $thumb_slashes . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : $thumb_slashes) . '\');' . "\n" . '//--></script>';
    
        $noscript_link = '<noscript>' . ($flag_display_large ? '<a href="' . zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large) . '" target="_blank">' . $thumb_regular . '<br /><span class="imgLinkAdditional">' . TEXT_CLICK_TO_ENLARGE . '</span></a>' : $thumb_regular ) . '</noscript>';
    
        //      $alternate_link = '<a href="' . $products_image_large . '" onclick="javascript:popupWindow(\''. $large_link . '\') return false;" title="' . $products_name . '" target="_blank">' . $thumb_regular . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>';
    
        $link = $script_link . "\n      " . $noscript_link;
        //      $link = $alternate_link;
    
        // List Box array generation:
        $list_box_contents[$row][$col] = array('params' => 'class="additionalImages centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
                                               'text' => "\n      " . $link);
        $col ++;
        if ($col > (IMAGES_AUTO_ADDED -1)) {
          $col = 0;
          $row ++;
        }
      } // end for loop
    } // endif
    To give you a brief overview... my website www.anglerscorner.co.uk has recently been upgraded from zencart version 1.3.9 to 1.5.4 and we also bought an updated theme. I developed the new site locally before going live with little trouble... however now the site site has gone live we seem to be having this issue.

    In case it helps, the site has the following modules installed:

    Snaf v1_2
    Cookie Control 1.4
    ceon uri mapping 4.5.0
    Backup MYSQL
    Easy Populate

    Apparently the this problem has become so severe that it has crashed our hosting server on more than one occasion, and our hosting company is really on our back about it... but has offered us little in the way of assistance to sort it out.

    Is there anybody out there who would be generous enough to advise if anything immediate stands out in the code I provided?
    Would really REALLY appreciate it.


    Thanks in advance,

    Mathew

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: preg_match(): Unknown modifier '0' ???

    Check your Private Messages
    Zen-Venom Get Bitten

  3. #3
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: preg_match(): Unknown modifier '0' ???

    What PHP version are you using?

    This is line 47:
    Code:
              if(preg_match('/\Q' . $products_image_base . '\E/i', $file) == 1) {
    The \Q and \E delimiters are basically saying "escape everything in between here", but maybe there's something in your actual image filename that's confusing it.
    Try changing the line to this instead:
    Code:
              if(preg_match('~' . preg_quote($products_image_base, '~') . '~i', $file) == 1) {
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Jan 2015
    Location
    United Kingdom
    Posts
    30
    Plugin Contributions
    0

    Default Re: preg_match(): Unknown modifier '0' ???

    Thank you very much for your reply.
    With much head banging I think I have identified the problem.

    Our Til's Epos system which links to Zencart seems to have developed a glitch when we upgraded and has inserted a '/' in in front of all of our image names.
    For example: /015868.jpg

    This has been resolved now by our software provider, however a lot of product image names have been affected.

    I have managed to export our product database, import the info into Open Office and do a Find/Replace to remove them.
    It seems to have gotten rid of the errors that we were getting.

    However, I have noticed that all our 'inactive' products still display the '/', this may still cause problems further down the line.
    I used Easy Populate to export the list and re-import it, is there any other way you can recommend for me to remove these '/' from all image names in my database?

    Please bear in mind I have very little experience with PHP and MySQL.

    Any help would be very much appreciated.


    Many thanks,

    Mathew

  5. #5
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: preg_match(): Unknown modifier '0' ???

    Did the code change I suggested provide the necessary relief? It should have, since it also changed the delimiter from / to ~ which would completely bypass the 0 being treated as a modifier.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Jan 2015
    Location
    United Kingdom
    Posts
    30
    Plugin Contributions
    0

    Default Re: preg_match(): Unknown modifier '0' ???

    Hi DrByte,

    Thank you so much for all of your help. Sorry for not replying until now, I had a three day weekend holiday and am only now seeing it.

    I somehow didn't actually notice your code change recommendation last week but I have given that a try now and will keep an eye on it.
    Thank you so much for all your help, really appreciate it :)

 

 

Similar Threads

  1. v139h Error: Unknown modifier '$' in main_product_image.php
    By divinelighting in forum General Questions
    Replies: 12
    Last Post: 27 Sep 2012, 10:26 AM
  2. Replies: 5
    Last Post: 15 Sep 2011, 03:16 PM
  3. preg_replace(): Unknown modifier 'h' in layout_controller.php
    By rashuweb in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 4 May 2011, 01:47 PM
  4. Replies: 2
    Last Post: 3 May 2010, 08:39 PM
  5. preg_match() Unknown modifier 'a' warning in Admin Additiona Images addon
    By dlamar in forum All Other Contributions/Addons
    Replies: 6
    Last Post: 26 Mar 2010, 03:20 PM

Posting Permissions

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