You are here

function str_replace_count in Table Alternate Rows 6

Same name and namespace in other branches
  1. 5 table_altrow.module \str_replace_count()

Replace every instance of a string with a count parameter like PHP5. This can probably be removed with Drupal goes to PHP5 only. Shamelessly stolen and modified from http://ca.php.net/manual/en/function.str-replace.php#76180

Parameters

string $needle:

string $replace:

string $haystack:

integer $count:

boolean $replace_first:

Return value

string

1 call to str_replace_count()
table_altrow_filter in ./table_altrow.module
Implementation of hook_filter

File

./table_altrow.module, line 108

Code

function str_replace_count($needle, $replace, $haystack, $offset = null, $count = null) {
  if ($count == null) {
    $count = 0;
  }
  if ($offset == null) {
    $offset = strpos($haystack, $needle);
  }
  $rpl_count = 0;
  while ($offset !== false && $rpl_count < $count) {
    $haystack = substr_replace($haystack, $replace, $offset, strlen($needle));
    $offset += strlen($replace);
    $offset = strpos($haystack, $needle, $offset);
    $rpl_count++;
  }
  return $haystack;
}