freakystreak Posted October 18, 2019 Share Posted October 18, 2019 I'm using 2.3.4.1 CE 'Frozen' and am trying to use add-on PDF Invoice 1.6 as a way to show orders as a PDF invoice. I thought I had it working but now this error appears: Warning: preg_replace(): Unknown modifier 'd' in /xxx/pdfinvoice.php on line 792 The line in question is $prod_attribs = preg_replace( $search_for, $change_to, $prod_attribs); This connects to these line too: $search_for = array( '/'.$currency_sym.'/', '/Â/', '(<[a-z/]*>)' ); $change_to = array( ' ', '', '' ); From what I've looked at it would refer to a delimiter but I just don't how to rectify this... any ideas? Ah, the world wide web. What a wonderful place. Link to comment Share on other sites More sharing options...
♥14steve14 Posted October 18, 2019 Share Posted October 18, 2019 It could be that preg_replace has been deprecated in some versions of php. Have a read here. https://stackoverflow.com/questions/16367404/how-to-convert-preg-replace-e-to-preg-replace-callback REMEMBER BACKUP, BACKUP AND BACKUP Link to comment Share on other sites More sharing options...
freakystreak Posted October 18, 2019 Author Share Posted October 18, 2019 Thanks @14steve14 for the quick reply. I forgot to add this line for the $currency_sym variable. $currency_sym = $currencies->format($order->info['currency']); $currency_sym = preg_replace( '([0-9Â.]*)', '', $currency_sym); I'm not great with kind of thing. Where is the 'd' that is trying to find? Ah, the world wide web. What a wonderful place. Link to comment Share on other sites More sharing options...
freakystreak Posted October 18, 2019 Author Share Posted October 18, 2019 Oh I'm using a server with php version 7.0.33 installed Ah, the world wide web. What a wonderful place. Link to comment Share on other sites More sharing options...
♥ecartz Posted October 18, 2019 Share Posted October 18, 2019 I would expect the modifier to be the thing after the ending delimiter, e.g. '/match/d' Maybe the currency symbol has a / in it? Perhaps try echoing it to the screen or logging it. I.e. either of print_r($search_for); error_log(print_r($search_for, true)); Put one or both of them right before line 792. Note that the first line might break your site under some circumstances. The second line is safer, but then you have to go spelunking in the logs to find the output. If this is in the admin, it's probably safe to use the first line (temporarily breaking the admin isn't a big deal; just remove the line to fix it). In the catalog, you should probably only do that on a test site, not your live shop. If that turns out to be the problem, try replacing $search_for = array( '/'.$currency_sym.'/', '/Â/', '(<[a-z/]*>)' ); with $search_for = array( '{'.$currency_sym.'}', '/Â/', '(<[a-z/]*>)' ); and see if that helps. Always back up before making changes. Link to comment Share on other sites More sharing options...
freakystreak Posted October 18, 2019 Author Share Posted October 18, 2019 thank you @ecartz. I tried your first suggestion and this is what it shows: Array ( [0] => / / [1] => /Â/ [2] => (<[a-z/]*>) ) Ah, the world wide web. What a wonderful place. Link to comment Share on other sites More sharing options...
♥ecartz Posted October 18, 2019 Share Posted October 18, 2019 Maybe try echo '<pre>'; print_r($search_for); echo '</pre>'; It seems to be hiding the actual content. It also may be visible in the HTML source if it's easier to look there than to add the pre tags. Always back up before making changes. Link to comment Share on other sites More sharing options...
freakystreak Posted October 18, 2019 Author Share Posted October 18, 2019 @ecartz ok, tried that and this is what i get: Array ( [0] => / / [1] => /Â/ [2] => (<[a-z/]*>) ) Ah, the world wide web. What a wonderful place. Link to comment Share on other sites More sharing options...
♥ecartz Posted October 18, 2019 Share Posted October 18, 2019 Hmm.... That doesn't seem as helpful as I'd hoped. Try changing $search_for = array( '/'.$currency_sym.'/', '/Â/', '(<[a-z/]*>)' ); to $search_for = array( '/'. preg_quote($currency_sym, '/') .'/', '/Â/', '(<[a-z/]*>)' ); And see if it still gives the same warning on the same line. I tend to agree that we're missing something. We should be able to answer 2 hours ago, freakystreak said: Where is the 'd' that is trying to find? I suppose it's barely possible that it's complaining about the currency symbol being empty. But I don't see how that gets us to a d. Always back up before making changes. Link to comment Share on other sites More sharing options...
freakystreak Posted October 18, 2019 Author Share Posted October 18, 2019 Thank you @ecartz that seems to have done the trick. The PDF is now showing. What did that new line do differently. Drinks are on me... Can i just thank you for helping me. Ah, the world wide web. What a wonderful place. Link to comment Share on other sites More sharing options...
♥ecartz Posted October 18, 2019 Share Posted October 18, 2019 A regular expression is supposed to be "starting delimiter", the regular expression, "ending delimiter", modifiers (if any). If the "ending delimiter" appears in the regular expression, it ends it early. So something like '//d/' is invalid, as it thinks that it is trying to match an empty regular expression under a d modifier. To fix that example, you could change it to '/\/d/' Which would match a forward slash followed by the letter d. But since the regular expression is generated dynamically from the currency symbol in this case, we can't just fix it. The preg_quote function goes through and escapes any regular expression syntax in the string. In particular, we told it the delimiter was a / and to escape any occurrences of that in the currency symbol. Or to put this another way, it would turn the first string into the second string. Always back up before making changes. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.