Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设一个字符串包含“包括”或“加入”。您将如何搜索和连接字符串中的连字符?
您可以使用正则表达式preg_replace():
preg_replace()
preg_replace('/-\s+/', '', $string);
这会查找 a-后跟一个或多个空格字符,并将它们替换为空字符串。
-
// -- Get an array of words splitted with '- ' $splitted = explode('- ', $word); // -- Rejoined words: $joined = implode('', $splitted );