0
Regular expression is not my strong suit in PHP and I need your help. I need to transform a string that comes from an apt post to be part of a url. Example:
"Caio didn’t take a bucket of water" for "caio-não-pegou-um-balde-Dagua" and then would be: com.br/caio-nao-pegou-um-balde-Dagua
Currently use eregi_replace and with PHP 7 no longer serves me, and then need a new way to run the same function.
Code:
public static function Url($texto){
$texto = html_entity_decode($texto);
$texto = @eregi_replace('[aáàãâä]','a',$texto);
$texto = @eregi_replace('[eéèêë]','e',$texto);
$texto = @eregi_replace('[iÃÂìîï]','i',$texto);
$texto = @eregi_replace('[oóòõôö]','o',$texto);
$texto = @eregi_replace('[uúùûü]','u',$texto);
$texto = @eregi_replace('[ç]','c',$texto);
$texto = @eregi_replace('[ñ]','n',$texto);
$texto = @eregi_replace('( )','-',$texto);
$texto = @eregi_replace('[^a-z0-9\-]','',$texto);
$texto = @eregi_replace('--','-',$texto);
return strtolower($texto);
}
Gabriel recommending the video on youtube https://www.youtube.com/watch?v=iPiTB4ho5DA =D. Here’s what you want http://thiagomorello.com/blog/2013/01/howto perfectly generate urls-friends-com-php/.
– Rafael Salomão