3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stripNonValidCharaters ($message) { $message = mb_convert_encoding($message, 'UTF-16', 'UTF-8'); $count = 0; //mostly taken from https://dynmark.uservoice.com/knowledgebase/articles/83496-gsm-alphabet-character-set $search = [ '`', '‘', '’', //single quotes '“', '”', //double quotes '~', '¬', '|', //misc chr(0xc2a0) //nbsp character ]; $replace = [ "'", "'", "'", //single quotes '"', '"', //double quotes '-', '-', 'I', //misc " " //space ]; $message = str_replace($search, $replace, $message, $count); $message = trim($message); return ['message' => $message, 'replacements' => $count]; } $message = "We can’t wait to see you at our Open Day next week. We’ve sent you an email with all the info you need. If you’ve not received it please call 01252 892883"; var_dump(stripNonValidCharaters($message));
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(2) { ["message"]=> string(307) "We can t wait to see you at our Open Day next week. We ve sent you an email with all the info you need. If you ve not received it please call 01252 892883" ["replacements"]=> int(0) }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/ufS7I on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/ufS7I on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/ufS7I on line 8
Process exited with code 255.

preferences:
233.12 ms | 401 KiB | 311 Q