note 124771 added to function.preg-replace

From: Date: Thu, 27 Feb 2020 17:27:59 +0000
Subject: note 124771 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-214240@lists.php.net to get a copy of this message
To replace double whitespace by a single space character in a sentence you need to use the \h modifier. It stands for horizontal whitespace. The more common \s modifier includes vertical whitespace such as line breaks, which is not good for saving paragraphs. Additionally, since most of todays code works with unicode strings you need to add the /u unicode modifier. I tried to replace four sequential normal spaces by one hyphen character resulting in '- - ' instead of '-'. I don't know why it works this way. <?php // Replace one or more horizontal white spaces // of any kind by one normal space character $str = preg_replace ('/\h+/u', ' ', $str); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 2001:981:9227:1:51:3c8c:2c05:5b19) ---- Manual Page -- http://php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/124771 Del: integrated -- https://master.php.net/note/delete/124771/integrated Del: useless -- https://master.php.net/note/delete/124771/useless Del: bad code -- https://master.php.net/note/delete/124771/bad+code Del: spam -- https://master.php.net/note/delete/124771/spam Del: non-english -- https://master.php.net/note/delete/124771/non-english Del: in docs -- https://master.php.net/note/delete/124771/in+docs Del: other reasons-- https://master.php.net/note/delete/124771 Reject -- https://master.php.net/note/reject/124771 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214240) next »