function split1($s) { $l = 0; $r = [""]; $j = strlen($s); $m = false; foreach (mb_str_split($s) as $c) { /* TODO optimize */ if ($c == "\\" and !$m) { $m = true; continue; } if ($m and $c != "\\") { $m = false; if ($c == "|" and $l == 0) { $r[] = ""; continue; } if ($c == "(" or $c == "[" or $c == "{") { $l += 1; } else { if ($c == "}" or $c == "]" or $c == ")") { $l -= 1; } } $c = "\\{$c}"; } array_push($r, array_pop($r) . $c); //var_dump($r[count($r)-1]); //var_dump($c); } return $r; }
/** * Calculates word's attributes. */ private function calculateAttributes() { $this->letterList = mb_str_split($this->word); $this->length = mb_strlen($this->word, 'UTF-8'); $this->firstLetter = $this->letterList[0]; $this->lastLetter = $this->letterList[$this->length - 1]; }
function test_mb_str_split() { $this->assertEquals(array('b', 'ö', 'b'), mb_str_split('böb')); $this->assertEquals(array('bö', 'b'), mb_str_split('böb', 2)); for ($i = 1; $i < 10; $i++) { $this->assertEquals(str_split('bob', $i), mb_str_split('bob', $i)); } $this->assertEquals(str_split('bobby'), mb_str_split('bobby')); $this->assertEquals(str_split(''), mb_str_split('')); }
/** * Create records from a data string. * * @param string $data * * @return array(Record) */ public function createRecords($data) { $records = array(); $size = $this->settings->get('recordSize'); $compression = $this->settings->get('compression'); $dataEntries = mb_str_split($data, $size); for ($i = 0, $len = sizeof($dataEntries); $i < $len; ++$i) { $records[$i] = new Record($dataEntries[$i]); $records[$i]->compress($compression); } return $records; }
/** * Multibyte version of ucwords(). * * @param string $str * @param string $delimiters * @param null|string $encoding * * @return mixed|string */ function mb_ucwords($str, $delimiters = " \t\r\n\f\v", $encoding = null) { $encoding = Std::coalesce($encoding, mb_internal_encoding()); $delimitersArray = mb_str_split($delimiters, 1, $encoding); $upper = true; $result = ''; for ($ii = 0; $ii < mb_strlen($str, $encoding); $ii++) { $char = mb_substr($str, $ii, 1, $encoding); if ($upper) { $char = mb_convert_case($char, MB_CASE_UPPER, $encoding); $upper = false; } elseif (ArrayList::of($delimitersArray)->includes($char)) { $upper = true; } $result .= $char; } return $result; }
/** * 1.6 style file matrix * * @param string $filename The filename * * @return string */ function file_matrix_1_6($filename) { $invalid_fs_chars = '*\'\\/"!$%^&*.%(){}[]#~?<>;|¬`@-+='; $matrix = ""; $name = $filename; $filename = mb_str_split($filename); if (!$filename) { return false; } $len = count($filename); if ($len > 5) { $len = 5; } for ($n = 0; $n < $len; $n++) { // Prevent a matrix being formed with unsafe characters $char = $filename[$n]; if (strpos($invalid_fs_chars, $char) !== false) { $char = '_'; } $matrix .= $char . "/"; } return $matrix . $name . "/"; }
$text_size = 30; # Limpio Lista de Glyphs $made_from = trim($made_from); // Trim $made_from = mb_strtolower($made_from, 'UTF-8'); // Paso a Minusculas $made_from = preg_replace('/\\s+/', '', $made_from); // Borro Espacios en blanco # Creo un Array limpito, con Frecuencia Zero function mb_str_split($string) { return preg_split('/(?<!^)(?!$)/u', $string); } mb_internal_encoding('UTF-8'); // Modo UTF-8 $made_from = array_unique(mb_str_split($made_from)); $made_from = array_flip($made_from); ksort($made_from); foreach ($made_from as $key => $value) { $made_from_as_array[$key] = 0; } # Funcion para buscar values que contengan una determinada string dentro de un array function my_array_find($needle, $haystack) { foreach ($haystack as $item) { if (strpos($item, $needle) !== FALSE) { return $item; break; } } }
$toprefix = "si"; } // echo "s: " . $prefix_sci[$startprefix] ." t: ".$prefix_sci[$toprefix]. " | "; if ((int) $prefix_sci[$startprefix] < (int) $prefix_sci[$toprefix]) { // echo " [s < t] ". ($round+1) ."<br>"; $operation = "-"; $sumprefix = abs($prefix_sci[$startprefix] - $prefix_sci[$toprefix]); } if ((int) $prefix_sci[$startprefix] > (int) $prefix_sci[$toprefix]) { // echo " [s > t] ". ($round+1) ."<br>"; $operation = "+"; $sumprefix = abs($prefix_sci[$toprefix] - $prefix_sci[$startprefix]); } // echo $sumprefix. ".. "; //convert the start value to sci value $startValueArr = mb_str_split($value); //echo $value. " - "; if ($value > 9) { // echo "bigger than 9 } "; while ((int) $value > 9) { $value = $value / 10; // echo $value. " - "; $exponent++; } } else { // echo "less than 1 } "; while ((int) $value < 1) { $value = $value * 10; //echo $value. " - "; $exponent--; }
</tr> </table> '; } echo ' <table border="1" cellspacing="0" style="width:100%; margin-top:10px;">'; $datos = mysql_query("SELECT a.nombre,a.id FROM horario h INNER JOIN materia m ON h.materia=m.id INNER JOIN area a ON m.area=a.id WHERE h.grupo='{$grupo}' AND h.anio='{$anio}' GROUP BY a.id ORDER BY a.nombre"); while ($reg = mysql_fetch_array($datos)) { $area = $reg['id']; $nomArea = $reg['nombre']; echo ' <tr> <td class="tdsAreas"> '; $nomArea = mb_strtoupper($nomArea, 'UTF-8'); $porciones = mb_str_split($nomArea); for ($i = 0; $i < count($porciones); $i++) { echo $porciones[$i] . "<br>"; } echo '</td> <td class="tdsInfoAreas"> <table cellspacing="0" border="1" style="width:100%;">'; $acomuladaArea = 0; $datos2 = mysql_query("SELECT m.id,m.nombre, m.porcentaje FROM horario h INNER JOIN materia m ON h.materia=m.id INNER JOIN area a ON m.area=a.id WHERE h.grupo='{$grupo}' AND h.anio='{$anio}' AND a.id='{$area}' GROUP BY h.materia ORDER BY m.nombre"); while ($reg2 = mysql_fetch_array($datos2)) { $materia = $reg2['id']; $nomMateria = $reg2['nombre']; $porcentajeMat = $reg2['porcentaje']; $faltas = 0; $datos3 = mysql_query("SELECT sum(falta) falta FROM faltas WHERE matricula='{$estInf}' AND materia='{$materia}' AND anio='{$anio}' "); while ($reg3 = mysql_fetch_array($datos3)) {
public static function split($string, $at = '') { if (empty($at)) { if (String::$multibyte) { return new Arr(mb_str_split($string)); } return new Arr(str_split($string)); } return new Arr(explode($at, $string)); }
/** * Money format * * @param mixed $amount * @param array $options * @return string */ public static function money_format($amount, $options = []) { $format = array_merge_hard(self::$options['locale_options'], $options['locale_options'] ?? []); $options['decimals'] = $options['decimals'] ?? 2; // sometimes symbols contain decimal point, we change it to thousands_sep if (!empty($options['symbol'])) { $options['symbol'] = str_replace($format['mon_decimal_point'], $format['mon_thousands_sep'], $options['symbol']); } else { $options['symbol'] = ''; } // convert to string if (!is_string($amount)) { $amount = $amount . ''; } $negative = strpos($amount, '-') !== false; $amount = ltrim($amount, '-'); // if the number portion has been formatted if (empty($options['amount_partially_formatted'])) { $temp = explode('.', $amount); $number = $temp[0]; $fraction = $temp[1] ?? ''; // process number if (empty($number)) { $number = '0'; } if ($format['mon_thousands_sep'] . '' !== '' && !empty($format['mon_grouping'])) { $counter = 0; $mon_grouping = []; $symbols = array_reverse(mb_str_split($number), true); $number = ''; foreach ($symbols as $k => $v) { // grab group size if ($counter == 0) { if (empty($mon_grouping)) { $mon_grouping = $format['mon_grouping']; } if (count($mon_grouping) > 1) { $counter = array_shift($mon_grouping); } else { $counter = $mon_grouping[0]; } } // skip number of characters $counter--; $number = $v . $number; if ($counter == 0 && $k > 0) { $number = $format['mon_thousands_sep'] . $number; } } } // left precision if (!empty($options['digits'])) { if (strlen($number) < $options['digits']) { $number = str_pad($number, $options['digits'], ' ', STR_PAD_LEFT); } } // right precision if ($options['decimals'] > 0) { $fraction = substr(str_pad($fraction, $options['decimals'], '0', STR_PAD_RIGHT), 0, $options['decimals']); $number = $number . $format['mon_decimal_point'] . $fraction; } } else { $number = $amount; } // translate characters $number = self::number_to_from_native_language($number, $options); // format based on settings $cs_precedes = $negative ? $format['n_cs_precedes'] : $format['p_cs_precedes']; $sep_by_space = $negative ? $format['n_sep_by_space'] : $format['p_sep_by_space']; $sign_posn = $negative ? $format['n_sign_posn'] : $format['p_sign_posn']; // if accounting formatting if (!empty($options['accounting'])) { // if we have currency symbol we added it based on settings if (!empty($options['symbol'])) { $number = ($cs_precedes ? $options['symbol'] . ($sep_by_space === 1 ? ' ' : '') : '') . $number . (!$cs_precedes ? ($sep_by_space === 1 ? ' ' : '') . $options['symbol'] : ''); } if ($negative) { $number = '(' . $number . ')'; } else { $number = ' ' . $number . ' '; } } else { $positive_sign = $format['positive_sign']; $negative_sign = $format['negative_sign']; $sign = $negative ? $negative_sign : $positive_sign; $other_sign = $negative ? $positive_sign : $negative_sign; $sign_padding = ''; if ($sign_posn) { for ($i = 0; $i < strlen($other_sign) - strlen($sign); $i++) { $sign_padding .= ' '; } } $temp_value = ''; switch ($sign_posn) { case 0: // parentheses surround value and currency symbol if (!empty($options['symbol'])) { $number = $cs_precedes ? $options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number : $number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']; } $number = '(' . $number . ')'; break; case 1: // sign precedes if (!empty($options['symbol'])) { $number = $cs_precedes ? $options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number : $number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']; } $number = $sign_padding . $sign . ($sep_by_space === 2 ? ' ' : '') . $number; break; case 2: // sign follows if (!empty($options['symbol'])) { $number = $cs_precedes ? $options['symbol'] . ($sep_by_space === 1 ? ' ' : '') . $number : $number . ($sep_by_space === 1 ? ' ' : '') . $options['symbol']; } $number = $number . ($sep_by_space === 2 ? ' ' : '') . $sign . $sign_padding; break; case 3: //sign precedes currency symbol $symbol = ''; if (!empty($options['symbol'])) { $symbol = $cs_precedes ? $options['symbol'] . ($sep_by_space === 1 ? ' ' : '') : ($sep_by_space === 2 ? ' ' : '') . $options['symbol']; } $number = $cs_precedes ? $sign_padding . $sign . ($sep_by_space === 2 ? ' ' : '') . $symbol . $number : $number . ($sep_by_space === 1 ? ' ' : '') . $sign . $sign_padding . $symbol; break; case 4: // sign succeeds currency symbol $symbol = ''; $symbol_sep = ''; if (!empty($options['symbol'])) { $symbol = $options['symbol']; $symbol_sep = $sep_by_space === 1 ? ' ' : ''; } $number = $cs_precedes ? $symbol . ($sep_by_space === 2 ? ' ' : '') . $sign_padding . $sign . $symbol_sep . $number : $number . $symbol_sep . $symbol . ($sep_by_space === 2 ? ' ' : '') . $sign . $sign_padding; break; } } return $number; }
$cuenta = substr_count($analizertwo, $letra); if ($cuenta == 0) { echo '<p style="color:red;">-</p>'; } else { $frequency = round($cuenta * 100 / $total_letters, 1); if ($frequency < 1) { echo '<p style="color:red;">' . $frequency . '%</p>'; } else { echo '<p>' . $frequency . '%</p>'; } } } echo '</td>'; echo '<td valign="top">'; # Creo un Array limpito, con Frecuencia Zero $made_from = array_unique(mb_str_split($analizertwo)); $new = my_array_find(' ', $made_from); if (($key = array_search($new, $made_from)) !== false) { unset($made_from[$key]); } $made_from = array_flip($made_from); ksort($made_from); foreach ($made_from as $key => $value) { $made_from_as_array[$key] = 0; } foreach ($made_from_as_array as $letra => $occurencias) { $made_from_as_array[$letra] = substr_count($analizertwo, $letra); } natsort($made_from_as_array); echo '<pre>'; print_r($made_from_as_array);
if ($user != 1 || $error == 1) { $reason = "Error!"; $message = "There was an issue with your account... Please Login and try again"; $dom = new DOMDocument("1.0", "UTF-8"); $XML = $dom->appendChild($dom->createElement('error')); $XML->setAttribute("xmlns:sql", "urn:schemas-microsoft-com:xml-sql"); $info = $XML->appendChild($dom->createElement('info')); $info->setAttribute("code", "526.14"); $info->setAttribute("reason", $reason); $info->setAttribute("message", $message); $info->setAttribute("action", "None"); } else { //Loads Armor String $armors = $char['strArmor']; //Converts string into Array $split = mb_str_split($armors, 1); //Sets New Value $split[$index] = $newval; //Combines Values $i = 0; while ($i <= 50) { $newastr = $newastr . $split[$i]; $i++; } //Saves String to DB $savestring = mysql_query("UPDATE df_characters SET strArmor='" . $newastr . "' WHERE ID='" . $char_id . "' LIMIT 1") or $error = 1; if ($error == 1) { $reason = "Error!"; $message = "Cannot save Armor Data."; $dom = new DOMDocument("1.0", "UTF-8"); $XML = $dom->appendChild($dom->createElement('error'));
/** * Split the string into smaller chunks. * * @param int $splitLength * * @return string[] * @throws \Exception */ public function split($splitLength = 1) { return mb_str_split($this->contents, $splitLength, $this->encoding); }
?> </h2> </div> <div style="float:right;"> <a href='player_games.php'><button class='btn btn-default btn-lg'>Δες όλα τα παιχνίδια</button></a> </div> </div> <?php // αν δεν υπάρχει το $_SESSION['word'], τότε διαλέγει λέξη και βάζει το επίπεδο δυσκολίας που επιλέχθηκε if (!isset($_SESSION['word'])) { include_once 'connect.php'; include_once 'choose_word.php'; $_SESSION['tries_left'] = $_SESSION['lives']; $len = mb_strlen($word); $_SESSION['word_array'] = mb_str_split($word); //μετατροπή λέξης σε πίνακα χαρακτήρων $print_word = array(); // ο παίκτης θα δει μόνο το πρώτο και το τελευταίο γράμμα της λέξης, τα ενδιάμεσα αντικαθίστανται από παύλες $print_word[0] = $_SESSION['word_array'][0]; for ($i = 1; $i < $len - 1; $i++) { $print_word[$i] = "_"; } $print_word[$len - 1] = $_SESSION['word_array'][$len - 1]; $_SESSION['print_word'] = $print_word; // δημιουργείται ο πίνακας με τα χρησιμοποιημένα γράμματα $_SESSION['used'] = array(); } if (isset($_POST['letter'])) { // έλεγχος γράμματος $_SESSION['used'][] = $_POST['letter'];
function query_to_tokens($string) { if (!is_string($string)) { return false; } $x = trim($string); // short circuit if the string is empty if (empty($x)) { return array(); } // tokenize string into individual characters $chars = mb_str_split($x); $mode = 'normal'; $token = ''; $tokens = array(); for ($i = 0, $j = count($chars); $i < $j; $i++) { switch ($mode) { case 'normal': if ($chars[$i] == '"') { if ($token != '') { $tokens[] = $token; } $token = ''; $mode = 'quoting'; } else { if (in_array($chars[$i], array(' ', "\t", "\n"))) { if ($token != '') { $tokens[] = $token; } $token = ''; } else { $token .= $chars[$i]; } } break; case 'quoting': if ($chars[$i] == '"') { if ($token != '') { $tokens[] = $token; } $token = ''; $mode = 'normal'; } else { $token .= $chars[$i]; } break; } } if ($token != '') { $tokens[] = $token; } return $tokens; }
/** * Handy function to help manage long strings by adding either an ellipsis or inserts a inserts a * <br /> at the position specified, and returns the result. * * @param string $str The string to manipulate. * @param string $length The max length of the string / place to insert <br /> * @param string $flag "ellipsis" / "page_break" * @return string The modified string. */ function ft_trim_string($str, $length, $flag = "ellipsis") { $new_string = ""; if (mb_strlen($str) < $length) { $new_string = $str; } else { if ($flag == "ellipsis") { $new_string = mb_substr($str, 0, $length) . "..."; } else { $parts = mb_str_split($str, $length); $new_string = join("<br />", $parts); } } return $new_string; }
public function generateCaptchaImage($captchaText, $imageFileName, $options) { //region parse settings from $options or use default values $width = Util::lavnn('width', $options, 180); // width of resulting captcha image $height = Util::lavnn('height', $options, 100); // height of resulting captcha image $paletteSize = Util::lavnn('paletteSize', $options, 7); // from how many random colors to choose $linePosition = mt_rand(30, 80); // the top margin for a text $letterPosition = mt_rand(10, 50); // coordinate of each rendered letter $fontFile = $this->r->config['folders']['fonts'] . Util::lavnn('font', $options, 'DejaVuSansMono') . '.ttf'; //endregion $captcha = imagecreate($width, $height); $backgroundColor = ImageColorAllocate($captcha, 255, 255, 255); //region Allocate colors, providing 150 as max value (colors should not be too close to white) $palette = array(); for ($i = 0; $i < $paletteSize; $i++) { $palette[] = ImageColorAllocate($captcha, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150)); } //endregion //region Add text that user should read foreach (mb_str_split($captchaText) as $letterCharacter) { $letterAngle = mt_rand(-18, 18); // each letter can be randomly inclined a little bit $letterSize = mt_rand(16, 28); // each letter can be of slightly different size $letterImageInfo = imagettftext($captcha, $letterSize, $letterAngle, $letterPosition, $linePosition, $palette[mt_rand(0, $paletteSize - 1)], $fontFile, $letterCharacter); $topRightX = $letterImageInfo[2]; $bottomRightX = $letterImageInfo[4]; // Calculate position for the next character $letterPosition = max($topRightX, $bottomRightX) + 5; } //endregion //region Add random lines and other graphical noise for ($i = 0; $i < $width * $height * 0.001; $i++) { imagesetthickness($captcha, 1); imageline($captcha, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $palette[mt_rand(0, $paletteSize - 1)]); } for ($i = 0; $i < $width * $height * mt_rand(5, 10) / 100; $i++) { imagesetpixel($captcha, mt_rand(1, $width), mt_rand(1, $height), $palette[mt_rand(0, $paletteSize - 1)]); } //endregion header('Content-Type: image/png'); imagepng($captcha, $imageFileName); imagedestroy($captcha); }
function get_letter($string) { $charlist = mb_str_split($string); return implode(array_map("getfirstchar", $charlist)); }
<?php /** * 字符串分割 */ $str = "Shanghai中国人ljdfl"; $time = microtime(1); var_dump(mb_str_split($str)); echo microtime(1) - $time; function mb_str_split($string) { return preg_split('/(?<!^)(?!$)/u', $string); }
if ($user != 1 || $error == 1) { $reason = "Error!"; $message = "There was an issue with your account... Please Login and try again"; $dom = new DOMDocument("1.0", "UTF-8"); $XML = $dom->appendChild($dom->createElement('error')); $XML->setAttribute("xmlns:sql", "urn:schemas-microsoft-com:xml-sql"); $info = $XML->appendChild($dom->createElement('info')); $info->setAttribute("code", "526.14"); $info->setAttribute("reason", $reason); $info->setAttribute("message", $message); $info->setAttribute("action", "None"); } else { //Loads Armor String $quests = $char['strQuests']; //Converts string into Array $split = mb_str_split($quests, 1); //Sets New Value $split[$index] = $newval; //Combines Values $i = 0; while ($i <= 50) { $newqstr = $newqstr . $split[$i]; $i++; } //Saves String to DB $savestring = mysql_query("UPDATE df_characters SET strQuests='" . $newqstr . "' WHERE ID='" . $char_id . "' LIMIT 1") or $error = 1; if ($error == 1) { $reason = "Error!"; $message = "Cannot save Quest Data."; $dom = new DOMDocument("1.0", "UTF-8"); $XML = $dom->appendChild($dom->createElement('error'));
if ($user != 1 || $error == 1) { $reason = "Error!"; $message = "There was an issue with your account... Please Login and try again"; $dom = new DOMDocument("1.0", "UTF-8"); $XML = $dom->appendChild($dom->createElement('error')); $XML->setAttribute("xmlns:sql", "urn:schemas-microsoft-com:xml-sql"); $info = $XML->appendChild($dom->createElement('info')); $info->setAttribute("code", "526.14"); $info->setAttribute("reason", $reason); $info->setAttribute("message", $message); $info->setAttribute("action", "None"); } else { //Loads Armor String $skills = $char['strSkills']; //Converts string into Array $split = mb_str_split($skills, 1); //Sets New Value $split[$index] = $newval; //Combines Values $i = 0; while ($i <= 20) { $newsstr = $newsstr . $split[$i]; $i++; } //Saves String to DB $savestring = mysql_query("UPDATE df_characters SET strSkills='" . $newsstr . "' WHERE ID='" . $char_id . "' LIMIT 1") or $error = 1; if ($error == 1) { $reason = "Error!"; $message = "Cannot save Skill Data."; $dom = new DOMDocument("1.0", "UTF-8"); $XML = $dom->appendChild($dom->createElement('error'));
<?php $input = getenv('POPCLIP_TEXT'); $output = ''; function mb_str_split($string) { # Split at all position not after the start: ^ # and not before the end: $ return preg_split('/(?<!^)(?!$)/u', $string); } $chars = mb_str_split($input); foreach ($chars as $c) { $val = ord($c); if ($val >= 32 && $val <= 126) { $output .= $c; } } echo $output;
function mb_strtr($str, $from, $to) { return str_replace(mb_str_split($from), mb_str_split($to), $str); }