We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    Hello
    I was wondering whether somebody has a function that would first, strip invalid attributes like "align" on an image tag and 2nd add e.g. the "alt" attribute if it’s missing.

    Unfortunately, I’m not good at this regexp stuff.

    Hope somebody can help.

    Thank you in advance for your input!!
      • 19889
      • 616 Posts
      I think I’m getting a little closer by using some of this stuff:
      <?php
      // fix RSS feed
      $str = '...';
      $output = str_replace('Weiterlesen...', $str, $output);
      // remove invalid align attribute
      $align = '/align=["\'](left|right)["\']/';
      $output = preg_replace($align, '', $output);
      
      // remove class tags
      $class = '/class=["\']([^"\']+)["\']/';
      $output = preg_replace($class, '', $output);
      
      $options = '<img>';
      return $modx->stripTags($output, $options);
      ?>
      


      I’m sure there are better ways to do it - however, I would still very much appreciate some input on how this cleanup could be achieved and what’s more important how I could an "alt" attribute if it’s missing on the image tag.

      thanks
      • TinyMCE should prompt you to enter the alt text or are you trying to do this without using tiny?
          Patrick | Server Wrangler
          About Me: Website | TweetsMODX Hosting
          • 19889
          • 616 Posts
          I’m not using tinyMCE at all and the code I’m after is to clean up an RSS feed.