Jump to content


Photo

converting character in a string to other characters


  • Please log in to reply
2 replies to this topic

#1 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 27 March 2006 - 07:05 PM

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

#2 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 27 March 2006 - 07:16 PM

[!--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) View Post[/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:
$string2 = eregi_replace( ",", "%", $string1);


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 March 2006 - 09:18 PM

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.
<?php $string2 = str_replace( ',', '%', $string1); ?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users