We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30128
    • 78 Posts
    Hi, I’m using FeedX for reading comic strip feeds and send the image from the feed to a javascript that use .innerHTML to swap images in a div.

    From a certain type of feeds the image comes packed inside HTML, which I can’t send directly to the javascript, so I need to parse it and get the content of the img src attribute only.

    Specifically, I’ll get the image to a FeedX placeholder ’[+DESCRIPTION+]’ typically containing a string like this:
    <img src="http://spray.nettavisen.no/shared/nemi/img/04.10.06.gif" border="0" />


    and need to parse it so I can send only this to the javascript:
    http://spray.nettavisen.no/shared/nemi/img/04.10.06.gif


    To do this, I’ve installed PHx and made a snippet ’phx:imgsrc’ like this:
    <?php
    $pattern = '\"(.+?)\"';
    preg_match($pattern,$output,$matches);
    return $matches[0];
    ?>
    


    I’ve tested the regexp in Komodo Rx Toolkit and it matches. I’ve also tested PHx and it works correctly.

    However when I try to use this modifier on the placeholder like this: ’[+DESCRIPTION:imgsrc+]’ I get this error:
    PHP error debug
      Error: 	preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash	 
      Error type/ Nr.: 	Warning - 2


    I’ve looked at a lot of online examples, and all uses backslashes to escape the double quote. I’ve tried a zillion different regular expressions but not managed to make a correct one!

    How can I write a PHx modifier that will do what I want?
      • 14050
      • 788 Posts
      I am not a regxp person, but you could probably use

      function textBetween($s1,$s2,$s){
        $s1 = strtolower($s1);
        $s2 = strtolower($s2);
        $L1 = strlen($s1);
        $scheck = strtolower($s);
      
        if($L1>0){$pos1 = strpos($scheck,$s1);} else {$pos1=0;}
        if($pos1 !== false){
         if($s2 == '') return substr($s,$pos1+$L1);
         $pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
         if($pos2!==false) return substr($s,$pos1+$L1,$pos2);
        }
        return '';
      }


      Then do something like textBetween("img src=", "/>", $output). Depending on what is actually being returned, you might have to replace some of those characters with the html entity that represents them.
        Jesse R.
        Consider trying something new and extraordinary.
        Illinois Wine

        Have you considered donating to MODx lately?
        Donate now. Every contribution helps.