Search
 
SCRIPT & CODE EXAMPLE
 

PHP

remove invalid characters from a string laravel

function hyphenize($string) {
    $dict = array(
        "I'm"      => "I am",
        "thier"    => "their",
        // Add your own replacements here
    );
    return strtolower(
        preg_replace(
          array( '#[s-]+#', '#[^A-Za-z0-9. -]+#' ),
          array( '-', '' ),
          // the full cleanString() can be downloaded from http://www.unexpectedit.com/php/php-clean-string-of-utf8-chars-convert-to-similar-ascii-char
          cleanString(
              str_replace( // preg_replace can be used to support more complicated replacements
                  array_keys($dict),
                  array_values($dict),
                  urldecode($string)
              )
          )
        )
    );
}

function cleanString($text) {
    $utf8 = array(
        '/[áàâãªä]/u'   =>   'a',
        '/[ÁÀÂÃÄ]/u'    =>   'A',
        '/[ÍÌÎÏ]/u'     =>   'I',
        '/[íìîï]/u'     =>   'i',
        '/[éèêë]/u'     =>   'e',
        '/[ÉÈÊË]/u'     =>   'E',
        '/[óòôõºö]/u'   =>   'o',
        '/[ÓÒÔÕÖ]/u'    =>   'O',
        '/[úùûü]/u'     =>   'u',
        '/[ÚÙÛÜ]/u'     =>   'U',
        '/ç/'           =>   'c',
        '/Ç/'           =>   'C',
        '/ñ/'           =>   'n',
        '/Ñ/'           =>   'N',
        '/–/'           =>   '-', // UTF-8 hyphen to "normal" hyphen
        '/[’‘‹›‚]/u'    =>   ' ', // Literally a single quote
        '/[“”«»„]/u'    =>   ' ', // Double quote
        '/ /'           =>   ' ', // nonbreaking space (equiv. to 0x160)
    );
    return preg_replace(array_keys($utf8), array_values($utf8), $text);
}
Comment

PREVIOUS NEXT
Code Example
Php :: keep line breaks in textarea 
Php :: laravel belongs to 
Php :: laravel blade if else condition 
Php :: php preg replace 
Php :: display data from two dimensional array in vew laravel 
Php :: remove square brackets from string php 
Php :: inplode php 
Php :: $ is not define in laravel 
Php :: acos() php 
Php :: add footer code 
Php :: get data without pivot relation laravel 
Php :: laravel eloquent get one column value 
Php :: composer create project laravel with version 
Php :: check if input file is empty in php 
Php :: laravel log package, laravel log, save laravel log 
Php :: Codeigniter 3 Pass anything in query string 
Php :: laravel faker 
Php :: PHP - AJAX and PHP 
Php :: post format wordpress 
Php :: laravel api 
Php :: laravel phpunit not run test 
Php :: how to check if a user is logged in in a non middleware controller in laravel 
Php :: ErrorException symlink(): No such file or directory 
Php :: test php code online free 
Php :: php ErrorException Undefined variable inside array_map 
Php :: Uncaught jquery-numerator requires jQuery to be loaded first wordpress 
Php :: rodar migration laravel 
Php :: php namespaces 
Php :: Laravel 8 Auth Scaffolding using Inertia Jetstream 
Php :: php remove duplicates from string 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =