Good all the time of day.

There is an algorithm that inclines the name. The algorithm does not give errors on the hosting, but gives errors on the local machine, even with the new version of the server. Hunting part of the code to rewrite, for this and appeal.

function rule ($rule) { preg_match("/^\s*([fm]?)\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*$/", $rule, $m); if ( $m ) return array ( "sex" => $m[1], "test" => split(',', $m[2]), "mods" => array ($m[3], $m[4], $m[5], $m[6], $m[7]) ); return false; } 

Mistake:

Deprecated: Function split() is deprecated in ...\skl.php on line 172

This line appears 40 times like this. I can show all the code, but I would like to rewrite this piece, an error on the line

 "test" => split(',', $m[2]), 

    3 answers 3

    Use explode (). The syntax is the same.

    there is still str_split($string,$piece_length) , but you need an expo

    PS However, there is a newer replacement for your function. Called she

     preg_split() 

    But in this case, when the breakdown goes one comma, regular expressions are clearly not needed.

    • 2
      The syntax is not the same. split accepts explode , explode accepts string. - Ali
    • The same in this case. =) - knes
    • Warning: preg_split () [function.preg-split]: No longer ending delimiter ',' found in ... \ skl.php on line 172 replaced with preg_split (). the same again. on the local machine error. on hosting also 8 ( - sergey
    • explode - worked. thank you so much - sergey
    • I wrote that it would be enough for more than. - knes

    Replace split with preg_split . It's not a mistake. It clearly explains to you - the function is declared deprecated.

    • Yes, dada .. it is the same. - knes

    after all the above, one small trouble arose, sometimes on the site of the resulting name, the error "Cannot parse supplied name" is displayed. what could it be?

    or

     Warning: preg_match() [function.preg-match]: Compilation failed: unrecognized character after (? or (?- at offset 2 in ...\skl.php on line 134 if (!isset($firstName)) { preg_match("/^\s*(\S+)(\s+(\S+)(\s+(\S+))?)?\s*$/", $lastName, $m); if(!$m) exit("Cannot parse supplied name"); if($m[5] && preg_match("/(ич|на)$/",$m[3]) && !preg_match("/(ич|на)$/",$m[5])) { // ошибка на строчку выше $lastName = $m[5]; $firstName = $m[1]; $middleName = $m[3]; $this -> fullNameSurnameLast = true; } else { // Сидоров Иван Петрович $lastName = $m[1]; $firstName = $m[3]; $middleName = $m[5]; } 
    • Compare how this name is different from the rest. Perhaps a lack or lack of words / commas? - knes
    • was: Ivanov Ivan Ivanovich - sergey
    • one
      I have a similar algorithm (pulled from some site). This happens if the value is not transmitted. just need to add a check. - Iukpun