3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php sms_message_parts("The fox"); function sms_message_parts($message) { // Message parts $parts = array(); // The default encoding is utf16 (unicode) until proven otherwise $encoding = 'utf16'; // Characters that are allowed in 7bit messages $gsm_7bit_chars = '@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&\'\(\)\*+,-\.\/0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà'; // Characters that are allowed in 7bit_ex messages $gsm_7bit_ex_chars = '\^{}\\\\\[~\]|€'; // Message lengths $message_lengths = array( '7bit' = > 160, '7bit_ex' = > 160, 'utf16' = > 70); // Detect encoding of message if (preg_match("/^[".$gsm_7bit_chars."]*$/u", $message) == 1) $encoding = '7bit'; elseif(preg_match("/^[".$gsm_7bit_chars.$gsm_7bit_ex_chars."]*$/u", $message) == 1) $encoding = '7bit_ex'; // Determine how long each part of the message can be $max_parts_length = $message_lengths[$encoding]; // Length of the message $message_length = mb_strlen($message, 'UTF-8'); // 7bit_ex message // Escaped characters found so we need to find the REAL length // and split the message differently if ($encoding == '7bit_ex') { // Count how many extra characters are required a result of // the 7bit_ex characters $extra_chars = 0; for ($i = 0; $i < $message_length; $i++) { if (preg_match("/^[".$gsm_7bit_ex_chars."]*$/u", mb_substr($message, $i, 1, 'UTF-8')) == 1) $extra_chars++; } // New message length $new_message_length = $message_length + $extra_chars; // Is this going to be a multipart message? if ($new_message_length > $max_parts_length) { // Split the message $start = 0; while (true) { // Determine the length of the split (if it's the last part, we don't need to look for // extra "escaped" characters) $last_part = false; $chars_left = $message_length - $start; if ($chars_left < $max_parts_length) { $split_length = $chars_left; $last_part = true; } else { $split_length = $max_parts_length; } // Extract the message part $part = mb_substr($message, $start, $split_length, 'UTF-8'); // Check to see if this part has any escaped characters $part_extra_chars = 0; if (!$last_part) { for ($i = 0; $i < $split_length; $i++) { if (preg_match("/^[".$gsm_7bit_ex_chars."]*$/u", mb_substr($part, $i, 1, 'UTF-8')) == 1) $part_extra_chars++; } } // If it has escaped characters, deduct from the amount of characters in this part // before adding to the parts array if ($part_extra_chars > 0) { $part = mb_substr($message, $start, ($split_length - $part_extra_chars), 'UTF-8'); $parts[] = trim($part); $start = $start + ($split_length - $part_extra_chars); // No escaped characters, add part to parts array } else { $parts[] = trim($part).' '.$split_length; $start = $start + $max_parts_length; } // We've reached the end of the message if ($start >= $message_length) break; } // It's a signle message } else { $parts[] = $message; } // 7bit and utf16 (unicode) messages don't have escaped characters } else { // Is this going to be a multipart message? Split this part before adding to the // parts array if ($message_length > $max_parts_length) { // Split the message into parts $total_messages = ceil($message_length / $max_parts_length); $start = 0; for ($i = 0; $i < $total_messages; $i++) { $parts[] = trim(mb_substr($message, $start, $max_parts_length, 'UTF-8')); $start = $start + $max_parts_length; } // It's a signle message } else { $parts[] = $message; } } return array('parts' = > $parts, 'encoding' = > $encoding); } ?>
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.4.36
Parse error: syntax error, unexpected '=', expecting ')' in /in/TQBAN on line 21
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '=', expecting ')' in /in/TQBAN on line 21
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/TQBAN on line 21
Process exited with code 255.