Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php function reverse($input) { $words = preg_split('/(\s+|[.,!?-])/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $reverse = 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('', $reverse); } 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;
Copy Clear