WildCard for str_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
albertpr9
Forum Newbie
Posts: 1
Joined: Sun May 16, 2010 6:28 pm

WildCard for str_replace

Post by albertpr9 »

Hi,

I've got a string that is 8-9 for example, and I'd like to convert it to 8'9, so I'll use

Code: Select all

str_replace("-", "'", $string);
the problem is sometimes the first number comes up as a negative, so it will show -8-7 and if I use the same code above, I'll end up with '8'7, which just won't make any sense.

So my question is, since the "-" sign that I'd like to change would only appear between two other numbers, what wild card can I use to make the code functional...

for example if "*" was a wild card I could just use

Code: Select all

str_replace("*-*", "'", $string);
So the real question I guess is what wild card can I use with str_replace to make this work.

Cheers, and thanks in advance for the help
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: WildCard for str_replace

Post by Weirdan »

Post Reply