如果我要替换几个单词/字符,如何组合ucwords和str_replace?

时间:2012-11-25 00:05:05

标签: php str-replace capitalize

如果我只需要替换一个字符,这可以合并ucwords和str_replace:

echo str_replace('_', ' ', ucwords($cname));

这可以替换单词/字符:

$search_name = array('_', ',', 'neckline', 'skirts', 'skirt','pants', 'neckline_size', 'sleeves', 'pants_length');
$replace_name = array(' ', ', ', '');
$rows = str_replace($search_name, $replace_name, $row);
echo $rows['silhouettes_like'];

但如果我尝试通过添加它来组合它们,它会回显“数组”而不是值

$style_names = ucwords($rows);

1 个答案:

答案 0 :(得分:1)

您希望array_map函数将ucwords映射到每个行值

$rows = array_map('ucwords', $rows);