Код: Выделить всё
$string= 'This is example string \add[name1]{added} and \remove[name2]{removed text} \change[name1]{this}{to}.'`
< р>
Код: Выделить всё
\remove[name2]{removed text}
Код: Выделить всё
\change[name1]{this}{to}
Ожидаемый результат
Код: Выделить всё
This is example string added and this.
Код: Выделить всё
preg_match('/\\add\[name1]{(.*?)}/',$string,$match) //for add (\add)
str_replace($match[0],$match[1],$match[0])
//problem is [name] is not constant so how to get the string between
//"\add[anything]{" and "}" I will apply same regex for this
//"\remove[anything]{" and "}" too.
Подробнее здесь: https://stackoverflow.com/questions/287 ... attributes