multiple test (regexp)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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
Say, I want to substitute "?", "*" and "°"...

How can I do?

Re: multiple test (regexp)

Maybe you should look up the built in function urlencode

Re: multiple test (regexp)

Quoted text here. Click to load it

Sorry for my example... but I need exactly what I asked, not url-
encoding   :-)

Re: multiple test (regexp) wrote:
Quoted text here. Click to load it


it's not clear from your post what exactly you're after

maybe strtr function helps you

$trans = array(
    '&' => "%26",
    '?' => "%3F",
    '%' => "%25",

echo strtr("a & b ? c % d", $trans);

gosha bine

extended php parser ~
blok ~

Re: multiple test (regexp)

On Sep 12, 2:54 pm, wrote:
Quoted text here. Click to load it

No regex needed -- just good old str_replace():

$b = str_replace(array('&', '?', '*'), '%26', $a);

Re: multiple test (regexp)

Thank you all!

Site Timeline