I got a slightly tricky preg_replace that I cannot figure out.
The string could be something like 2:456:982:12:89:
Let’s say I want to remove just the “2:” and replace it with nothing.
Here is what I have with $focus_chat being “2”:
preg_replace('/:' . $focus_chat . ':/', ':', $unfocus_chat);
Now, this would work if the 2: was in the middle of the string. The problem with this is that the 2: will not have a : first since it is at the beginning of the string.
Any ideas? Thank you!
You can say: Beginning of string (that is
^) or::Also added end of string (
$) for the second delimiter.