This should do it::
Main Topics
Browse All TopicsHi e's, usually I use str_replace for substitute special characters for a space ' ', and I use with a string, in this way:
==========================
$string = str_replace(array('.',',',
==========================
Now I want use str_replace with array_map, because I have a array with a lot of keys, and I want substitute in all keys the special characters.
Regards, JC
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
@cxr, I have a array with many keys, and I want replace all special characters for ' '(space).
Usually I do with a string, but with a array I don't know how I do that.
I need to replace in all values of the array.
Example of a key:
[0] => the, great. Day)
return [0] => the great Day)
@jessegivy I try your solution in this way but don't work.
==========================
$regra = str_replace(array('.',',',
$list = array_map(create_function(
//$hh1total[1] contain:
Array
(
[0] => tags relacionadas
[1] => tags relacionadas
[2] => bookmarks de jaspion
)
Regards, JC
The way I understand it array_map operates on the values of the array, so if you want to call str_replace on the keys then you've got to array_flip before calling array_map per my example. then flip the return value back so that the keys and values are correct. lookup the array_flip function on php.net for more info if interested.
Cheers,
Jesse
@cxr, I test your solution:
===============
# Because parameters 2 and 3 are the same for all invocations, a helper function is better:
function array_str_replace($param) {
return str_replace(array('.',',',
'@','"','[',']','<','>','+',
}
$keys = array('the, great. Day', 'Another Great! Day', '!!test!!', 'correct?'); # four items
$res = array_map('array_str_repla
var_dump($res);
===================
In the first view the code work well, tell me just if that code is prepare to receive aleatory number of keys, because not is always four keys, sometimes is 1, other 5, other 20 and so one!
Regards, JC
Business Accounts
Answer for Membership
by: cxrPosted on 2009-06-02 at 11:40:07ID: 24529979
Please be more specific about what kind of array you have and what results you want. Can you show an example?