How can I add something to replace all multiple spaces in a string, with only single spaces in the below regex?. Everything else in the below code needs to remain as it is. I'm only trying to add the replace multiple spaces part.
The other part in there replaces multiple hyphens with a single one.
$name = preg_replace('#[ -]+#', '-', $rawName);
$name = preg_replace('#\s+#', ' ', $rawName);
Try this : that should kee only one space between words
{
$var = str_replace(' ','',$var);
}
尝试这个
$str = preg_replace( "/\s+/", " ", $data );
$output = preg_replace('!\s+!', ' ', $input);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.