As from the text ssilka-na --- top to make sure that there is at most one dash ssilka-na-top

It is necessary to look in the line --- and replace with - . Or is there an easier way?

  • one
    preg_replace( '/\-{2,}/','-', $str ); - Visman

2 answers 2

 $mystring = 'ssilka-na---top'; echo preg_replace( '/--+/','-', $mystring ); 

    Replace 2 or more hyphens with one, for example using a regular expression:

     $ php -r "var_dump (preg_replace ('/ \ - + /', '-', 'ssilka-na --- top'));"
     string (13) "ssilka-na-top"
    
    • sorry) @ zenden2k was the first - emtecif