Good evening.
I currently have a string that has values that are seperated by '|'
Because of some strange anomalies in a loop sometimes the '|' doubles up to appear as '||' or even '|||'
Is there any way to simply search the string for occurnces of the two and three | and replace them with a single |?
Thanks in advance
Replacing a character in a string
Moderator: General Moderators
Re: Replacing a character in a string
Curious why that's a good idea, but whatever.
Code: Select all
$new = preg_replace('/\|\|+/', '|', $old);Re: Replacing a character in a string
That does it, cheerrrs our felllaa
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Replacing a character in a string
Agreed, it's never a good idea to fix a bug by adding ad-hoc code that post-processes to remove the result of the bug. It gets messy very quickly.McInfo wrote:Wouldn't it be better to find out why the pipes are doubling up?