Notes & Code Snippets

Read notes about design & development, or useful scripts and bits of code from me

Replace content in a string within delimiters

November 23, 2009

Keywords: str string replace delimit delimiters php

This script replaces content inside delimiters with whatever you want. It's like using str_replace when you only know the beginning and end of the string to be replaced.
function replace_content_inside_delimiters($start, $end, $new, $source) {
	return preg_replace('#('.preg_quote($start).')(.*)('.preg_quote($end).')#si', $new, $source);
}

Back to top