我正在尝试在PHP中将单引号引起来。
我已经显示了每个步骤的结果。我不知道如何在每个名称周围加上“”?
我可以做到这一点,Listen Up, Case Studies, Publications
但我需要结果看起来像这样'Listen Up', 'Case Studies', 'Publications'
$categories = $wlrs_cats[0]['content_type'];
$value = implode(',', $categories);
// $value = content-type/listen-up/,content-type/case-studies/,content-type/publications/
$result = ucwords(strtr($value, ["content-type/"=>" '", "/"=>"'", "-"=>" "]), "' ");
// $result; // 'Listen Up', 'Case Studies', 'Publications'
我会提出一个更简单的解决方案,$string
您的原始格式如下content-type/listen-up/,content-type/case-studies/,content-type/publications/
:
$result = ucwords(strtr($string, ["content-type/"=>" '", "/"=>"'", "-"=>" "]), "' ");
因此,您替换了某些内容,然后大写说明('
和space
)后跟的单词。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句