|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello, I use this code: $a = "&&&&&& a b c d e f g"; $b = ereg_replace ("&", "%26", $a); echo $b; to subtitute every "&" occurrence in $a. What if I want to change other occurrences of other chars at the same time? Say, I want to substitute "?", "*" and "°"... How can I do? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Maybe you should look up the built in function urlencode
http://uk.php.net/manual/en/function.urlencode.php |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> http://uk.php.net/manual/en/function.urlencode.php Sorry for my example... but I need exactly what I asked, not url- encoding :-) |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
pepper.gabriela@gmail.com wrote:
> Hello, I use this code: > > > $a = "&&&&&& a b c d e f g"; > $b = ereg_replace ("&", "%26", $a); > > echo $b; > > to subtitute every "&" occurrence in $a. > > What if I want to change other occurrences of other chars at the same > time? > Say, I want to substitute "?", "*" and "°"... > > How can I do? > hi it's not clear from your post what exactly you're after maybe strtr function s you $trans = array( '&' => "%26", '?' => "%3F", '%' => "%25", ); echo strtr("a & b ? c % d", $trans); -- gosha bine extended php parser ~ http://code.google.com/p/pihipi blok ~ http://www.tagarga.com/blok |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Sep 12, 2:54 pm, pepper.gabri...@gmail.com wrote:
> Hello, I use this code: > > $a = "&&&&&& a b c d e f g"; > $b = ereg_replace ("&", "%26", $a); > > echo $b; > > to subtitute every "&" occurrence in $a. > > What if I want to change other occurrences of other chars at the same > time? > Say, I want to substitute "?", "*" and "°"... > > How can I do? No regex needed -- just good old str_replace(): $b = str_replace(array('&', '?', '*'), '%26', $a); |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Thank you all! |
|
![]() |
| Outils de la discussion | |
|
|