Jump to content

Archived

This topic is now archived and is closed to further replies.

essjay_d12

converting character in a string to other characters

Recommended Posts

i need to directly change a string $string to $string2

but whenever there is a , in $string it needs to change it to a % in $string2

thanks

d

Share this post


Link to post
Share on other sites
[!--quoteo(post=358988:date=Mar 27 2006, 02:05 PM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 27 2006, 02:05 PM) [snapback]358988[/snapback][/div][div class=\'quotemain\'][!--quotec--]
i need to directly change a string $string to $string2

but whenever there is a , in $string it needs to change it to a % in $string2

thanks

d
[/quote]

you could try:
[code]$string2 = eregi_replace( ",", "%", $string1);[/code]

Share this post


Link to post
Share on other sites
Why not use the [a href=\"http://www.php.net/str_replace\" target=\"_blank\"]str_replace[/a]() function, since it doesn't have the overhead of using regular expressions.
[code]<?php $string2 = str_replace( ',', '%', $string1); ?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.