Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Aneildo

[Resolvido] erro com preg_replace

Recommended Posts

eu axei uma função na net para limpar texto para url, mas qnd eu vo usá tá dando os seguintes erros

 

Warning: preg_replace() [function.preg-replace]: Compilation failed: invalid UTF-8 string at offset 3 in C:\xampp\htdocs\nti\test.php on line 4

 

Warning: preg_replace() [function.preg-replace]: Compilation failed: invalid UTF-8 string at offset 3 in C:\xampp\htdocs\nti\test.php on line 5

 

Warning: preg_replace() [function.preg-replace]: Compilation failed: invalid UTF-8 string at offset 3 in C:\xampp\htdocs\nti\test.php on line 6

 

Warning: preg_replace() [function.preg-replace]: Compilation failed: invalid UTF-8 string at offset 3 in C:\xampp\htdocs\nti\test.php on line 7

 

Warning: preg_replace() [function.preg-replace]: Compilation failed: invalid UTF-8 string at offset 2 in C:\xampp\htdocs\nti\test.php on line 8

 

Warning: preg_replace() [function.preg-replace]: Compilation failed: invalid UTF-8 string at offset 2 in C:\xampp\htdocs\nti\test.php on line 9

 

Warning: preg_replace() [function.preg-replace]: Compilation failed: invalid UTF-8 string at offset 1 in C:\xampp\htdocs\nti\test.php on line 10

 

 

<?php
function clean($texto) {
	$texto = html_entity_decode($texto);
	$texto = preg_replace('![aáàãâä]+!u','a',$texto);
	$texto = preg_replace('![eéèêë]+!u','e',$texto);
	$texto = preg_replace('![iíìîï]+!u','i',$texto);
	$texto = preg_replace('![oóòõôö]+!u','o',$texto);
	$texto = preg_replace('![uúùûü]+!u','u',$texto);
	$texto = preg_replace('![ç]+!u','c',$texto);
	$texto = preg_replace('![ñ]+!u','n',$texto);
	$texto = eregi_replace('( )','-',$texto);
	$texto = preg_replace('![^a-z0-9\-]+!u','',$texto);
	$texto = eregi_replace('--','-',$texto);
	
	return strtolower($texto);
}
$a = clean('çãó4');
echo $a;
?>

se alguém poder me ajudar eu agradeço muito

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tire os 'u' da E.R.

 

EX:

$texto = preg_replace('![aáàãâä]+!','a',$texto);
$texto = preg_replace('![eéèêë]+!','e',$texto);
$texto = preg_replace('![iíìîï]+!','i',$texto);
$texto = preg_replace('![oóòõôö]+!','o',$texto);
$texto = preg_replace('![uúùûü]+!','u',$texto);
$texto = preg_replace('![ç]+!','c',$texto);
$texto = preg_replace('![ñ]+!','n',$texto);
$texto = eregi_replace('( )','-',$texto);
$texto = preg_replace('![^a-z0-9\-]+!','',$texto);
$texto = eregi_replace('--','-',$texto);

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tire os 'u' da E.R.

 

EX:

 $texto = preg_replace('![aáàãâä]+!','a',$texto);
 $texto = preg_replace('![eéèêë]+!','e',$texto);
 $texto = preg_replace('![iíìîï]+!','i',$texto);
 $texto = preg_replace('![oóòõôö]+!','o',$texto);
 $texto = preg_replace('![uúùûü]+!','u',$texto);
 $texto = preg_replace('![ç]+!','c',$texto);
 $texto = preg_replace('![ñ]+!','n',$texto);
 $texto = eregi_replace('( )','-',$texto);
 $texto = preg_replace('![^a-z0-9\-]+!','',$texto);
 $texto = eregi_replace('--','-',$texto);

Renato Siroma, obrigado pela a ajudar

Compartilhar este post


Link para o post
Compartilhar em outros sites

lucasmartins.com.br

 

Este tópico é antigo como pode observar na data, seu post foi excluído. Crie um novo tópico para postar sua dúvida.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.