Joined September 2011
·

Simon Kohlmeyer

Germany/Karlsruhe
·
·
·

Posted to Wordpress responsive images! over 1 year ago

Parsing html with regular expressions has several problems, for example you don't handle single quotes.

Here's a solution using http://simplehtmldom.sourceforge.net/

require 'include/simple_html_dom.php';
 function bootstrap_responsive_images( $html ){
  $classes = ['img-responsive'];

  $dom = str_get_html($html);
  foreach($dom->find('img') as $img) {
    $img_classes = explode(" ", $img->class);
    $img_classes = array_unique(array_merge($img_classes, $classes));
    $img->classes = implode(" ", $img_classes);

    $img->width = null;
    $img->height = null;
  }

  return (string) $dom;
}
Posted to Faster Git Clones over 1 year ago

Note that this only works with git 1.9 and up, see http://stackoverflow.com/questions/6941889/is-git-clone-depth-1-shallow-clone-more-useful-than-it-makes-out

The manpage has been corrected in recent git versions, as referenced on in the question linked above.

Achievements
58 Karma
0 Total ProTip Views