regex - How to convert 3 or more spaces to a hyphen conditionally in php -


i want convert multiple spaces hyphen.

for example, if there 3 or more consecutive spaces between words in string, want convert them hyphen.

original string :

 $x="hello    world! new        here. 

string after execution:

 hello-world! new-here  

i have tried following, not seem work properly.

 <?php  $str="hello    world! new     here";  echo preg_replace("/.*\s{3}/","-",$str);  

please,try this:-

<?php $str="hello    world! new     here";  echo preg_replace("/\s{3,}/","-",$str); ?> 

output:-http://prntscr.com/7bd9nk

note: take care of number number of spaces equal or greater 3. thanks.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -