How can i replace unused section in content. For example:
$content = "
Test content
[section]
Section Content
[section]
End.
";
$content = preg_replace('/\[section\](.*)\[section\]/', '', $content);
Thanks
How can i replace unused section in content. For example:
$content = "
Test content
[section]
Section Content
[section]
End.
";
$content = preg_replace('/\[section\](.*)\[section\]/', '', $content);
Thanks
The s
modifier allows a dot metacharacter in the pattern to match all characters, including newlines.
The i
modifier is used for case-insensitive matching allowing both upper and lower case letters. By adding the quantifier ?
it makes for a non greedy match and matches the least amount possible.
$content = preg_replace('/\[section\].*?\[section\]/si', '', $content);
See Demo
What's the regex for? This should work and will run a lot quicker:
$content = explode('[section]',$content);
$content = $content[0].$content[2];