public function AceFilter::strReplaceOnce in Ace Code Editor 8
Custom function to replace the code only once.
Probably not the most efficient way, but at least it works.
1 call to AceFilter::strReplaceOnce()
- AceFilter::process in src/
Plugin/ Filter/ AceFilter.php - Processing the filters and return the processed result.
File
- src/
Plugin/ Filter/ AceFilter.php, line 206
Class
- AceFilter
- Filters implementation for Ace Editor.
Namespace
Drupal\ace_editor\Plugin\FilterCode
public function strReplaceOnce($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));
}