replace hyphen with underline htaccess

Asked

Viewed 80 times

0

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

www.site.com.br/post/77-eu_tu_eles          

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 ]), will return a array, the $delimiter past, in our case is the "-". The $delimiter is used as a parameter for separating string.

And then we use the implode ( string $glue , array $pieces ), where we took the array function returned explode, that is stored in the variable $urlExplode, and spent a $glue to merge the values of the array, which in this case is "_".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.