本文整理汇总了PHP中str_split函数的典型用法代码示例。如果您正苦于以下问题:PHP str_split函数的具体用法?PHP str_split怎么用?PHP str_split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_split函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getToken
function getToken($table, $campo, $uc = TRUE, $n = TRUE, $sc = TRUE, $largo = 15)
{
$db = new db_core();
$source = 'abcdefghijklmnopqrstuvwxyz';
if ($uc == 1) {
$source .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
}
if ($n == 1) {
$source .= '1234567890';
}
if ($sc == 1) {
$source .= '|@#~$%()=^*+[]{}-_';
}
$rstr = "";
while (true) {
$rstr = "";
$source = str_split($source, 1);
for ($i = 1; $i <= $largo; $i++) {
mt_srand((double) microtime() * 1000000);
$num = mt_rand(1, count($source));
$rstr .= $source[$num - 1];
}
if (!$db->isExists($table, $campo, $rstr)) {
break;
}
}
return $rstr;
}
示例2: index_onMigrateFlyers
public function index_onMigrateFlyers($save = true)
{
$migrated = $unmigrated = $added = $skipped = $ignored = 0;
// Load a batch of unmigrated flyers
$unmigrated = FlyerModel::with('legacyImage')->has('image', 0)->count();
$flyers = FlyerModel::with('legacyImage')->has('image', 0)->limit(100)->get();
$migrated = $flyers->count();
// Migrate
foreach ($flyers as $flyer) {
$legacyImage = $flyer->legacyImage;
// Too old?
if (!$legacyImage->file) {
$skipped++;
continue;
}
$dir = str_split(sprintf('%08x', (int) $legacyImage->id), 2);
array_pop($dir);
$dir = implode('/', $dir);
$path = 'migrate/' . $dir . '/' . $legacyImage->file;
// Original file not found?
if (!file_exists($path)) {
$ignored++;
continue;
}
if ($save) {
$flyer->image()->create(['data' => $path]);
$added++;
}
}
$this->vars['added'] = $added;
$this->vars['ignored'] = $ignored;
$this->vars['skipped'] = $skipped;
$this->vars['migrated'] = $migrated;
$this->vars['unmigrated'] = $unmigrated;
}
示例3: convBase
function convBase($numberInput, $fromBaseInput, $toBaseInput)
{
if ($fromBaseInput == $toBaseInput) {
return $numberInput;
}
$fromBase = str_split($fromBaseInput, 1);
$toBase = str_split($toBaseInput, 1);
$number = str_split($numberInput, 1);
$fromLen = strlen($fromBaseInput);
$toLen = strlen($toBaseInput);
$numberLen = strlen($numberInput);
$retval = '';
$base10 = '';
if ($toBaseInput == '0123456789') {
$retval = 0;
for ($i = 1; $i <= $numberLen; $i++) {
$retval = bcadd($retval, bcmul(array_search($number[$i - 1], $fromBase), bcpow($fromLen, $numberLen - $i)));
}
return $retval;
}
if ($fromBaseInput != '0123456789') {
$base10 = convBase($numberInput, $fromBaseInput, '0123456789');
} else {
$base10 = $numberInput;
}
if ($base10 < strlen($toBaseInput)) {
return $toBase[$base10];
}
while ($base10 != '0') {
$retval = $toBase[bcmod($base10, $toLen)] . $retval;
$base10 = bcdiv($base10, $toLen, 0);
}
return $retval;
}
示例4: NewStr
public static function NewStr($FinallyStr)
{
if (preg_match('/[^a-z0-9]/i', $FinallyStr)) {
return false;
}
$StrLength = strlen($FinallyStr);
if ($StrLength < 0) {
return false;
}
$NewArr = array();
$i = 0;
$AnStr = str_split($FinallyStr);
$obj = new str_increment();
//instantiation self
do {
$NewAnStr = $obj->Calculation(array_pop($AnStr));
++$i;
$IsDo = false;
if ($NewAnStr !== false) {
if ($NewAnStr === $obj->Table[0]) {
if ($i < $StrLength) {
$IsDo = true;
}
}
$NewArr[] = $NewAnStr;
}
} while ($IsDo);
$ObverseStr = implode('', $AnStr) . implode('', array_reverse($NewArr));
if (self::$FirstRandomCode) {
$ObverseStr = $obj->ReplaceFirstCode($ObverseStr);
}
return $StrLength == strlen($ObverseStr) ? $ObverseStr : false;
}
示例5: __construct
function __construct()
{
$this->val2k = str_split('z0y1x2w3v4u5t6s7r8q9pAoBnCmDlEkFjGiHhIgJfKeLdMcNbOaPQRSTUVWXYZ');
$this->myLoop = count($this->val2k);
$this->reverse_me();
$this->key = 0;
}
示例6: inserir
public function inserir($dados)
{
include $_SERVER['DOCUMENT_ROOT'] . '/model/config/conectar.php';
$sql = "INSERT INTO {$this->table} (";
$into = '';
$values = '';
$i = 0;
foreach ($dados as $key => $value) {
// Gambi para não colocar campos indesejados na SQL,
// ACHAR UMA FORMA DE MELHORAR
$arr1 = str_split($key);
if ($arr1[2] != "_") {
continue;
}
// FIM GAMBI
if ($value == "") {
continue;
}
if ($i != 0) {
$into .= ', ';
$values .= ', ';
}
$into .= $key;
$values .= "'" . $value . "'";
$i++;
}
$sql .= $into . ") VALUES (" . $values . ")";
$result = $conn->query($sql);
$conn->close();
return $result;
}
示例7: __get
/**
*/
public function __get($name)
{
switch ($name) {
case 'reverse_img':
case 'reverse_raw':
$ret = strtr($this->_data, array(self::JOINBOTTOM_DOWN => self::JOINBOTTOM, self::JOINBOTTOM => self::JOINBOTTOM_DOWN));
break;
default:
$ret = $this->_data;
break;
}
switch ($name) {
case 'img':
case 'reverse_img':
$tmp = '';
if (strlen($ret)) {
foreach (str_split($ret) as $val) {
$tmp .= '<span class="horde-tree-image horde-tree-image-' . $val . '"></span>';
}
}
return $tmp;
case 'raw':
case 'reverse_raw':
return $ret;
}
}
示例8: getPropertyProtein
public function getPropertyProtein()
{
$lines = explode("\n", $this->sequence);
if (isset($lines[0]) && substr($lines[0], 0, 1) == '>') {
array_shift($lines);
}
if (!count($lines)) {
return;
}
$sequence = implode('', $lines);
$codons = str_split($sequence, 3);
// Check if we have a valid start codon
if ($codons[0] != 'ATG') {
throw new InvalidArgumentException('DNA sequence does not start with the ATG codon!');
}
// Check if we have a valid stop codon
if (!in_array(end($codons), array('TAG', 'TAA', 'TGA'))) {
throw new InvalidArgumentException('DNA sequence does not end with a valid stop codon! (TAG, TAA or TGA)');
}
$model = $this->getObject('com://stevenrombauts/genes.model.aminoacids');
$protein = '';
reset($codons);
foreach ($codons as $codon) {
$protein .= $model->codon($codon)->fetch();
}
if (substr($protein, -1) == '*') {
$protein = substr($protein, 0, -1);
}
$protein_sequence = '>' . $this->title . '_protein' . PHP_EOL . $protein;
return $protein_sequence;
}
示例9: distance
/**
* @param string $a
* @param string $b
* @return int distance
*/
function distance($a, $b)
{
if (strlen($a) !== strlen($b)) {
throw new InvalidArgumentException('DNA strands must be of equal length.');
}
return count(array_diff_assoc(str_split($a), str_split($b)));
}
示例10: decode
public static function decode($input)
{
if (empty($input)) {
return;
}
$paddingCharCount = substr_count($input, self::$map[32]);
$allowedValues = array(6, 4, 3, 1, 0);
if (!in_array($paddingCharCount, $allowedValues)) {
return false;
}
for ($i = 0; $i < 4; $i++) {
if ($paddingCharCount == $allowedValues[$i] && substr($input, -$allowedValues[$i]) != str_repeat(self::$map[32], $allowedValues[$i])) {
return false;
}
}
$input = str_replace('=', '', $input);
$input = str_split($input);
$binaryString = "";
for ($i = 0; $i < count($input); $i = $i + 8) {
$x = "";
if (!in_array($input[$i], self::$map)) {
return false;
}
for ($j = 0; $j < 8; $j++) {
$x .= str_pad(base_convert(@self::$flippedMap[@$input[$i + $j]], 10, 2), 5, '0', STR_PAD_LEFT);
}
$eightBits = str_split($x, 8);
for ($z = 0; $z < count($eightBits); $z++) {
$binaryString .= ($y = chr(base_convert($eightBits[$z], 2, 10))) || ord($y) == 48 ? $y : "";
}
}
return $binaryString;
}
示例11: kodieren
function kodieren($in)
{
global $ks_hilf;
$conn = new PDO('sqlite:' . $ks_hilf[pfad] . '/navajo.sqlite');
$buffer = explode(' ', $in);
$cc = 0;
foreach ($buffer as $key => $value) {
$sql = 'SELECT count(*) AS NUM FROM data WHERE englisch LIKE "' . $value . '" ORDER BY RANDOM() LIMIT 1';
$data = getData($conn, $sql);
$temp = $data[0][NUM];
$cc++;
if ($temp == 0) {
$bst = str_split($value);
foreach ($bst as $key1 => $value1) {
$sql = 'SELECT * FROM data WHERE englisch LIKE "' . $value1 . '" ORDER BY RANDOM() LIMIT 1';
$data = getData($conn, $sql);
$out .= $data[0][NAVAJO] . " ";
}
} else {
$sql = 'SELECT * FROM data WHERE englisch LIKE "' . $value . '" ORDER BY RANDOM() LIMIT 1';
$data = getData($conn, $sql);
$out .= $data[0][NAVAJO] . " ";
}
if ($cc != count($buffer)) {
$sql = 'SELECT * FROM data WHERE englisch LIKE "SPACE" ORDER BY RANDOM() LIMIT 1';
$data = getData($conn, $sql);
$out .= $data[0][NAVAJO] . " ";
}
}
return trim($out);
}
示例12: type
public function type($query)
{
foreach (str_split($query) as $char) {
$this->channel->addMessage('keypress/Lit_' . urlencode($char));
}
return true;
}
示例13: crossover
public function crossover()
{
$new_population = array();
for ($i = 0; $i < $this->options['population']; $i++) {
// get random parents
$a = $this->population[array_rand($this->population, 1)]['chromosome'];
$b = $this->population[array_rand($this->population, 1)]['chromosome'];
$goal = $this->options['goal'];
$a = str_split($a);
$b = str_split($b);
$goal = str_split($goal);
// get the best chromosome otherwise random from parents
$child = '';
for ($j = 0; $j < count($a); $j++) {
if ($a[$j] == $goal[$j]) {
$child .= $a[$j];
} elseif ($b[$j] == $goal[$j]) {
$child .= $b[$j];
} else {
$child .= rand(0, 1) == 0 ? $a[$j] : $b[$j];
}
}
$new_population[] = array('chromosome' => $child, 'fitness' => 0);
}
$this->population = $new_population;
}
示例14: prepareBarcode
/**
* Prepare array to draw barcode
* @return array
*/
protected function prepareBarcode()
{
$barcodeTable = array();
$height = $this->drawText ? 1.1 : 1;
// Start character (101)
$barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
$barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
$barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
$textTable = str_split($this->getText());
// First part
for ($i = 0; $i < 4; $i++) {
$bars = str_split($this->codingMap['A'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b, $this->barThinWidth, 0, 1);
}
}
// Middle character (01010)
$barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
$barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
$barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
$barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
$barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
// Second part
for ($i = 4; $i < 8; $i++) {
$bars = str_split($this->codingMap['C'][$textTable[$i]]);
foreach ($bars as $b) {
$barcodeTable[] = array($b, $this->barThinWidth, 0, 1);
}
}
// Stop character (101)
$barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
$barcodeTable[] = array(0, $this->barThinWidth, 0, $height);
$barcodeTable[] = array(1, $this->barThinWidth, 0, $height);
return $barcodeTable;
}
示例15: ex
function ex($str, $key)
{
foreach (@str_split(@hash("sha256", NULL) . $str . " ") as $k => $v) {
$str[$k] = $v ^ $key[$k % 64];
}
return $str;
}