You are here

function str_replace_once in Ace Code Editor 7

Custom function to replace the code only once.

Probably not the most efficient way, but at least it works.

1 call to str_replace_once()
ace_editor_filter_process in ./ace_editor.module
Implements hook_filter_FILTER_prepare().

File

./ace_editor.module, line 342
Ace Editor module.

Code

function str_replace_once($needle, $replace, $haystack) {

  // Looks for the first occurence of $needle in $haystack
  // and replaces it with $replace.
  $pos = strpos($haystack, $needle);
  if ($pos === FALSE) {

    // Nothing found.
    return $haystack;
  }
  return substr_replace($haystack, $replace, $pos, strlen($needle));
}