SMcClean Posted December 29, 2011 Share Posted December 29, 2011 Hi there, I am NOT a PHP coder, but I have a site that is written in PHP and I am getting an error that keeps filling up my site cache and I just cannot figure it out - I know it has something to do with my images on the site, but none of them are out of the ordinary (GIFs and JPEGs, the only character apart from letters or numbers that i have used is the "_" and there are no spaces). I have looked around at the error I am getting - but I will be honest in that I dont really understand what the problem is or how to resolve it. Here is the error I get: PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Unknown modifier 'C' in /home/smcclean/public_html/includes/modules/additional_images.php on line 48 This relates to the following line of code: if(preg_match("/" . $products_image_base . "/i", $file) == 1) { I would really appreciate a steer as to how I could resolve this. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/254013-preg_match-unknown-modifier/ Share on other sites More sharing options...
kicken Posted December 29, 2011 Share Posted December 29, 2011 My guess is that your $products_image_base variable contains a '/' character, possibly as a directory separator. you'd have to print the variable to see what it contains. Since your using '/' as your regex delimiter, any instances of '/' inside your regex (in the variable) must be escaped by prefixing them with a '\' character. preg_quote should be able to take care of this for you. Quote Link to comment https://forums.phpfreaks.com/topic/254013-preg_match-unknown-modifier/#findComment-1302166 Share on other sites More sharing options...
SMcClean Posted December 29, 2011 Author Share Posted December 29, 2011 Hi, thank you for your reply. One of my image directories is using the "/" separator. How do I "allow" this to be the case? I am not sure what a regex is......apologies, I really do not know PHP! Is there something I can add to the line of code that allows the use of the "/"? Quote Link to comment https://forums.phpfreaks.com/topic/254013-preg_match-unknown-modifier/#findComment-1302175 Share on other sites More sharing options...
ManiacDan Posted December 29, 2011 Share Posted December 29, 2011 The easiest solution is to simply do: if(preg_match("/" . preg_quote($products_image_base) . "/i", $file) == 1) { Explaining WHY would take too long, and you're not a coder anyway. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/254013-preg_match-unknown-modifier/#findComment-1302177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.