php - 在字符串周围加上撇号?
问题描述
我试图在 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
) 后面的单词。
推荐阅读
- java - JAVA EMAIL API 上的错误(无法解析 javax.mail.Authenticator 类型。它是从所需的 .class 文件中间接引用的)
- c - 如何使用leaks 命令行工具查找内存泄漏?
- python - 在 Sublime 编辑器中出现错误:Python 代码
- c++ - 如何理解赋值表达式“a=(b=4)=3”
- javascript - 如何比排序更快地找到数组的最大子集?
- perl - 生成公钥/私钥并在 Perl 中使用 Crypt::OpenSSL::RSA 对其进行签名
- python - ** 在 Python 中是什么意思?
- swift - SwiftUI 向动画文本添加不必要的“dot dot dot”
- macos - PS1 env 无法在新的 mac Catalina 上解析
- javascript - 使用 react-snap 后视频不会自动播放