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
Post a Comment