• Hi,

    I use BJ Lazy Load, and i love it.
    But i found a specific bug with preg_replace in the file class-bjll.php (line 327)

    • When you have a very VERY long content, (>2000 char)
    • And you set a not-lazy class in options’ plugins (like “no-lazy”)
    • The preg_replace take too long (more than 60s) in my server (and i a powerfull one).

    So i add a little modification in this file :

    OLD :

    public static function remove_skip_classes_elements( $content ) {
    
    		$skip_classes = self::_get_skip_classes( 'html' );
    
    		/*
    		https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
    		We can’t do this, but we still do it.
    		*/
    		$skip_classes_quoted = array_map( 'preg_quote', $skip_classes );
    		$skip_classes_ORed = implode( '|', $skip_classes_quoted );
    
    		$regex = '/<\s*\w*\s*class\s*=\s*[\'"]?(|.*\s)?' . $skip_classes_ORed . '(|\s.*)?[\'"]?.*?>/isU';
    
    		return preg_replace( $regex, '', $content );
    	}

    Become :

    public static function remove_skip_classes_elements( $content ) {
    
    		$skip_classes = self::_get_skip_classes( 'html' );
    
    		/*
    		https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454
    		We can’t do this, but we still do it.
    		*/
    		$skip_classes_quoted = array_map( 'preg_quote', $skip_classes );
    		$skip_classes_ORed = implode( '|', $skip_classes_quoted );
    
    		$regex = '/<\s*\w*\s*class\s*=\s*[\'"]?(|.*\s)?' . $skip_classes_ORed . '(|\s.*)?[\'"]?.*?>/isU';
    		if(strlen($content)>2500) // TOO LONG CONTENT : Preg_replace will take too long to execute !
    			return $content;
    		else
    			return preg_replace( $regex, '', $content );
    	}

    I think, it will be great to review this function or to add a parameter on option page to skip big content (>2000 char).

    I think, this could help some people so i post it here.
    Thanks a lot for this plugin.
    And have a nice day

    PS : I’m a french dude, so sorry for my bad english.

  • The topic ‘Problem with class-bjll.php – preg_replace’ is closed to new replies.