You are here

private function CSSmin::substring in Advanced CSS/JS Aggregation 6

PHP port of Javascript's "substring" function Author: Tubal Martin http://blog.margenn.com Tests: http://margenn.com/tubal/substring/

Parameters

string $str:

int $from index:

int|bool $to index (optional):

Return value

string

2 calls to CSSmin::substring()
CSSmin::compress_hex_colors in advagg_css_compress/yui/CSSMin.inc
Utility method to compress hex color values of the form #AABBCC to #ABC or short color name.
CSSmin::extract_data_urls in advagg_css_compress/yui/CSSMin.inc
Utility method to replace all data urls with tokens before we start compressing, to avoid performance issues running some of the subsequent regexes against large strings chunks.

File

advagg_css_compress/yui/CSSMin.inc, line 653

Class

CSSmin

Code

private function substring($str, $from = 0, $to = FALSE) {
  if ($to !== FALSE) {
    if ($from == $to || $from <= 0 && $to < 0) {
      return '';
    }
    if ($from > $to) {
      $from_copy = $from;
      $from = $to;
      $to = $from_copy;
    }
  }
  if ($from < 0) {
    $from = 0;
  }
  $substring = $to === FALSE ? substr($str, $from) : substr($str, $from, $to - $from);
  return $substring === FALSE ? '' : $substring;
}