PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php function reverse($input) { $words = preg_split('/(\s+|[.,!?-])/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $reversedWords = array_map(function($word) { if (preg_match('/[.,!?-]/', $word)) { return $word; } else { return mb_strrev(preg_replace('/[.,!?-]/u', '', $word), 'UTF-8') . preg_replace('/\p{L}+/u', '', $word); } }, $words); return implode('', $reversedWords); } function mb_strrev($input, $encoding = 'UTF-8') { $length = mb_strlen($input, $encoding); $reversed = ''; while ($length-- > 0) { $reversed .= mb_substr($input, $length, 1, $encoding); } return $reversed; } $input = "Куда идём мы с Пятачком - Большой-большой секрет!"; $out = reverse($input); echo $out;
Show:  
Copy Clear