[英]How to replace a character with white space from a given string in php?
$country = preg_replace(array('/^\[/','/\]$/'), '',$country);
这样将根据此问题在文本中的任何位置删除方括号
但是可以说我们有:
United_arab_emirates
我们如何才能做到这一点:
United Arab Emirates
?
注意:此处不是php专家*
这就是我尝试过的(由于这里的答案之一)
$custom_country = usp_get_meta(false, 'usp-custom-3');
$custom_country = htmlspecialchars_decode($custom_country);
$custom_country = nl2br($custom_country);
$country = preg_replace(array('_'), ' ',$country);
echo ucfirst($custom_country);
结果仍然是United_arab_emirates
最快的方法是两个步骤:
码:
$country = str_replace('_', ' ', $country);
$country = ucwords($country);
$country = preg_replace(array('[_]'), ' ',$country);
或者你可以只使用字符串替换
$country = str_replace("_"," ",$country);
如果_
是唯一需要替换的额外字符,则可以使用str_replace
:
$country = str_replace("_", " ", $country);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.