Im getting some odd error messages on a site of mine. The strange thing is I have a local copy which works fine and this one which isnt: you can see the error at the top of the homepage (and only the homepage) at http://sourceymonkey.com/

warning: preg_replace(): Unknown modifier 'j' in modules/delicious/delicious.module on line 831.
warning: preg_replace(): Unknown modifier 'w' in modules/delicious/delicious.module on line 834.
warning: preg_replace(): Unknown modifier 'j' in modules/delicious/delicious.module on line 831.

and that line number is..

830    if (!preg_match('/<.+>/',$text)) {
831        $text = preg_replace('/(\b'.$tag.'\b)/i','$1'.$deliciousLink,$text);
832      } 
833      else {
834        $text = preg_replace('/(?<=>)([^<]+)?(\b'.$tag.'\b)/i','$1$2'.$deliciousLink,$text);
835      }

Comments

merlinofchaos’s picture

Hmm. It looks to me like there are \ characters in your tags? In fact, there's a few bits of punctuation that could cause problems like this, now that I look at the code. Could you give me a var_export of the $tags variable in that function?

willwade’s picture

if (!preg_match('/<.+>/',$text)) {
        $text = preg_replace('/(\b'.$tag.'\b)/i','$1'.$deliciousLink,$text);
        print "<code>preg_replace('/(\b'.$tag.'\b)/i','$1'.$deliciousLink,$text);

\n";

}
else {
$text = preg_replace('/(?<=>)([^<]+)?(\b'.$tag.'\b)/i','$1$2'.$deliciousLink,$text);
print " preg_replace('/(?<=>)([^<]+)?(\b'.$tag.'\b)/i','$1$2'.$deliciousLink,$text) \n";
}

see http://sourceymonkey.com for the output

willwade’s picture

just edited the printing a bit.
in short its having problems with slashes and tags with "-"

e.g.
<code>warning: preg_replace(): Unknown modifier 'w' in /home/helpmonk/public_html/modules/delicious/delicious.module on line 831.

tag: phone-s/w deliciousLink: Only local images are allowed. , text:

tag: java/jsp deliciousLink: Only local images are allowed. , text:

warning: preg_replace(): Unknown modifier 'w' in /home/helpmonk/public_html/modules/delicious/delicious.module on line 837.[else]tag: phone-s/w deliciousLink: Only local images are allowed. , text:

etc..

cheers

merlinofchaos’s picture

Try this:

      if (!preg_match('/<.+>/',$text)) {
        $text = preg_replace('/(\b'.preg_quote($tag_.'\b)/i','$1'.$deliciousLink,$text);
      } 
      else {
        $text = preg_replace('/(?<=>)([^<]+)?(\b'.preg_quote($tag).'\b)/i','$1$2'.$deliciousLink,$text);

The only change is the addition of preg_quote()

willwade’s picture

It sadly doesnt - and I havent got a clue why. Your quite right. It should..
Here's my current code:

 $tag = preg_quote($tag);
      
      if (!preg_match('/<.+>/',$text)) {
        if(!$text = preg_replace('/(\b'.$tag.'\b)/i','$1'.$deliciousLink,$text)){
          print "tag: ".$tag."\n";
		}
      } 
      else {
        if (!$text = preg_replace('/(?<=>)([^<]+)?(\b'.$tag.'\b)/i','$1$2'.$deliciousLink,$text)){
          print "[else]tag: ".$tag." \n";
        }
      }

still looking..

willwade’s picture

Ok, the only way I can get the error messages suppressed is if I do the following:

$path = "http://del.icio.us/$username/$tag";
      $deliciousLink = "<a href = \"$path\"><img src = \"modules/delicious/deliciousIcon.gif\" border = \"0\" style = \"margin: 0px; padding: 0px; vertical-align: middle;\"></a>";
      $tag = preg_quote($tag);
      $tag = str_replace('/','\/',$tag);

Im not sure thats the best approach - it will do some strange things to a system where preg_quote actually works!

no idea why its not working sadly :(

merlinofchaos’s picture

Oh! I'm a dork!

Use:

$tag = preg_quote($tag, '/');

preg_quote doesn't get the / by default, you have to add it. I need to read the documentation more closely.

willwade’s picture

cool

another one bites the dust.. :)

merlinofchaos’s picture

Status: Active » Fixed

Committed to HEAD.

merlinofchaos’s picture

Assigned: Unassigned » merlinofchaos
Status: Fixed » Active

I'm re-opening this. There's another side-effect of having '/' in tags -- you can't link to them. Since it's two very different symptoms of the same basic problem, I'm keeping it in this bug.

merlinofchaos’s picture

Status: Active » Fixed

New bug opened for the remaining problem after all.

Anonymous’s picture

Status: Fixed » Closed (fixed)