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.35
Parse error: syntax error, unexpected ''“'' (T_CONSTANT_ENCAPSED_STRING), expecting ']' in /in/W9FdF on line 10
Process exited with code 255.
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/W9FdF 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/W9FdF on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/W9FdF on line 8
Process exited with code 255.

preferences:
216.05 ms | 1395 KiB | 125 Q