replace hyphen by underline htaccess

0

How to replace the hyphen next to the number by underline in that URL (htaccess).

www.site.com.br/post/77-eu_tu_eles          
    
asked by anonymous 01.11.2017 / 18:46

1 answer

1
$url = "www.site.com.br/post/77-eu_tu_eles";

$urlExplode = explode("-",$url);
$urlImplode = implode("_",$urlExplode);

With the function explode( string $delimiter , string $string [, int $limit ]) , it will return a array , the $delimiter passed, in our case it is the "-". The $delimiter is used as a parameter for separating the string .

And soon after we use implode ( string $glue , array $pieces ) , where we get the array returned from the explode function, which is stored in the variable $urlExplode , and pass $glue to merge% , which in this case is "_".

    
01.11.2017 / 19:44