Alex Lian Alex Lian - 3 months ago 15
PHP Question

regex, remove all but one character in PHP

I need your help.

I need to remove a pattern from a text file

,"refresh":18});


But I don't need to delete curly bracket in this pattern, I need to save it.

My code

...
echo $data2 = str_replace(",\"refresh\":18});", "", $data);
...


How to change my regex to remove the pattern, but don not remove } charecter ?

Answer

Why don't you just replace the whole pattern with character '}' ??? Just try:

echo str_replace(",\"refresh\":18});", "}", $data);