essjay_d12 Posted March 27, 2006 Share Posted March 27, 2006 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 $string2thanksd Link to comment https://forums.phpfreaks.com/topic/5947-converting-character-in-a-string-to-other-characters/ Share on other sites More sharing options...
lead2gold Posted March 27, 2006 Share Posted March 27, 2006 [!--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 $string2thanksd[/quote]you could try:[code]$string2 = eregi_replace( ",", "%", $string1);[/code] Link to comment https://forums.phpfreaks.com/topic/5947-converting-character-in-a-string-to-other-characters/#findComment-21294 Share on other sites More sharing options...
kenrbnsn Posted March 27, 2006 Share Posted March 27, 2006 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 Link to comment https://forums.phpfreaks.com/topic/5947-converting-character-in-a-string-to-other-characters/#findComment-21339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.