Str: preg_replace(): No ending delimiter '-' found

Asked

Viewed 460 times

0

Ola could help me where exactly put the delimiters in the code below?

    function simplifica($txt){
    $txt = strtolower($txt);
    $txt = str_replace(array('á','à','â','ã','å','ä','ª','Á','À','Â','Ã','Ä'), 'a', $txt);
    $txt = str_replace(array('é','è','ê','ë','É','È','Ê','Ë'), 'e', $txt);
    $txt = str_replace(array('í','ì','î','ï','Í','Ì','Î','Ï'), 'i', $txt);
    $txt = str_replace(array('ó','ò','ô','õ','ö','º','Ó','Ò','Ô','Õ','Ö'), 'o', $txt);
    $txt = str_replace(array('ú','ù','û','ü','Ú','Ù','Û','Ü'), 'u', $txt);
    $txt = str_replace(array('ñ','Ñ'), 'n', $txt);
    $txt = str_replace(array('ç','Ç'), 'c', $txt);
    /*
    $txt = ereg_replace('[áàâãåäªÁÀÂÄÃ]', 'a', $txt);
    $txt = ereg_replace('[íìîïÍÌÎÏ]', 'i', $txt);
    $txt = ereg_replace('[éèêëÉÈÊË]', 'e', $txt);
    $txt = ereg_replace('[óòôõöºÓÒÔÕÖ]', 'o', $txt);
    $txt = ereg_replace('[úùûüÚÙÛÜ]', 'u', $txt);
    $txt = ereg_replace('[ñÑ]', 'n', $txt);
    $txt = ereg_replace('[çÇ]', 'c', $txt);
    */
    $txt = preg_replace("\n|\t|\r", '', $txt);
    $txt = preg_replace('[ ]+', ' ', $txt); // de 2 espaços p/ nada
    $txt = preg_replace('[ ]', '-', $txt); // de 2 espaços p/ nada (denovo)
    $txt = preg_replace('-+', '-', $txt); // de 2 espaços p/ nada (denovo)
    return preg_replace('/([^a-z0-9-]*)/', '', $txt);
  • What is the input (initial value of $txt) and the expected result?

  • edit it, I put the full function ! , I get the error : Str: preg_replace(): Unknown Modifier

  • the expected result is to correct the backend of a ready site system ! http://demo.sisfacil.com.br/

  • migrated php5.2 server to 5.4 , then suffering a lot since then to correct so many errors

  • Do you know which line the error is on? Have a stack trace?

2 answers

0


You forgot again to put the delimiters on preg_replace.

function simplifica($txt){
    $txt = strtolower($txt);
    $txt = str_replace(array('á','à','â','ã','å','ä','ª','Á','À','Â','Ã','Ä'), 'a', $txt);
    $txt = str_replace(array('é','è','ê','ë','É','È','Ê','Ë'), 'e', $txt);
    $txt = str_replace(array('í','ì','î','ï','Í','Ì','Î','Ï'), 'i', $txt);
    $txt = str_replace(array('ó','ò','ô','õ','ö','º','Ó','Ò','Ô','Õ','Ö'), 'o', $txt);
    $txt = str_replace(array('ú','ù','û','ü','Ú','Ù','Û','Ü'), 'u', $txt);
    $txt = str_replace(array('ñ','Ñ'), 'n', $txt);
    $txt = str_replace(array('ç','Ç'), 'c', $txt);

    $txt = preg_replace("/\n|\t|\r/", '', $txt);
    $txt = preg_replace("/[ ]+/", ' ', $txt); // de 2 espaços p/ nada
    $txt = preg_replace("/[ ]/", '-', $txt); // de 2 espaços p/ nada (denovo)
    $txt = preg_replace("/-+/", '-', $txt); // de 2 espaços p/ nada (denovo)
    return preg_replace('/([^a-z0-9-]*)/', '', $txt);
}
  • valeeeuuu ,,,, ; )

0

I found the function below in another forum and I think it responds well to this question:

function tirarAcentos($string){<br>
    $string2 = preg_replace(array("/(á|à|ã|â|ä)/","/(Á|À|Ã|Â|Ä)/","/(é|è|ê|ë)/","/(É|È|Ê|Ë)/","/(í|ì|î|ï)/","/(Í|Ì|Î|Ï)/","/(ó|ò|õ|ô|ö)/","/(Ó|Ò|Õ|Ô|Ö)/","/(ú|ù|û|ü)/","/(Ú|Ù|Û|Ü)/","/(ñ)/","/(Ñ)/", "/(ç|Ç)/"),explode(" ","a A e E i I o O u U n N c"),$string);<br>
    return $string2;<br>
}

Browser other questions tagged

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