Method replace()
- Method replace
string
replace(string
s
,string
from
,string
to
)
string
replace(string
s
,array
(string
)from
,array
(string
)to
)
string
replace(string
s
,array
(string
)from
,string
to
)
string
replace(string
s
,mapping
(string
:string
)replacements
)
array
replace(array
a
,mixed
from
,mixed
to
)
mapping
replace(mapping
a
,mixed
from
,mixed
to
)- Description
Generic replace function.
This function can do several kinds replacement operations, the different syntaxes do different things as follows:
If all the arguments are strings, a copy of
s
with every occurrence offrom
replaced withto
will be returned. Special case:to
will be inserted between every character ins
iffrom
is the empty string.If the first argument is a string, and the others array(string), a string with every occurrance of
from
[i] ins
replaced withto
[i] will be returned. Instead of the arraysfrom
andto
a mapping equvivalent tomkmapping(
can be used.from
,to
)If the first argument is an array or mapping, the values of
a
which are `==() withfrom
will be replaced withto
destructively.a
will then be returned.- Note
Note that replace() on arrays and mappings is a destructive operation.