Jump to content


multi-str_replace[SOLVED]


2 replies to this topic

#1 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 20 July 2007 - 11:44 PM

I have signatures in profiles on a website i'm making, and I want to get rid of some of those "pesky" things.
Like when a user puts in a hundred exclamation points :\
Well, i'm using str_replace like this:
$signature = str_replace("!!", "!", $signature);
Not sure if there's a better way to do this, or if I could do some kind of while loop to have it work?
Anyway, what it does now, is removes one of them each time the form is submitted, unless of course there is only one there. The problem is, It needs to remove all of them except one, and isn't.
Hope this makes sense & that there is a simple solution, i've looked around for str_replace methods, but I haven't come across anything that does this. :\

Edited by tgs, 21 July 2007 - 01:19 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 July 2007 - 02:56 AM

Regex.
$signature = preg_replace('#!+#', '!', $signature);


#3 pirateXcore

    Young Padawan

  • Members
  • Pip
  • 281 posts
  • Gender:Male

Posted 21 July 2007 - 01:18 PM

DOH!

Thank you, I feel like a freakin idiot. :lol:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users