本文整理汇总了PHP中pos函数的典型用法代码示例。如果您正苦于以下问题:PHP pos函数的具体用法?PHP pos怎么用?PHP pos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pos函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fill
function fill($prefix, $listid)
{
global $server_name, $tables, $table_prefix;
# check for not too many
$domain = getConfig("domain");
$res = Sql_query("select count(*) from {$tables['user']}");
$row = Sql_fetch_row($res);
if ($row[0] > 50000) {
error("Hmm, I think 50 thousand users is quite enough for a test<br/>This machine does need to do other things you know.");
print '<script language="Javascript" type="text/javascript"> document.forms[0].output.value="Done. Now there are ' . $row[0] . ' users in the database";</script>' . "\n";
return 0;
}
# fill the database with "users" who have any combination of attribute values
$attributes = array();
$res = Sql_query("select * from {$tables['attribute']} where type = \"select\" or type = \"checkbox\" or type=\"radio\"");
$num_attributes = Sql_Affected_rows();
$total_attr = 0;
$total_val = 0;
while ($row = Sql_fetch_array($res)) {
array_push($attributes, $row["id"]);
$total_attr++;
$values[$row["id"]] = array();
$res2 = Sql_query("select * from {$table_prefix}" . "listattr_" . $row["tablename"]);
while ($row2 = Sql_fetch_array($res2)) {
array_push($values[$row["id"]], $row2["id"]);
$total_val++;
}
}
$total = $total_attr * $total_val;
if (!$total) {
Fatal_Error("Can only do stress test when some attributes exist");
return 0;
}
for ($i = 0; $i < $total; $i++) {
$data = array();
reset($attributes);
while (list($key, $val) = each($attributes)) {
$data[$val] = pos($values[$val]);
if (!$data[$val]) {
reset($values[$val]);
$data[$val] = pos($values[$val]);
}
next($values[$val]);
}
$query = sprintf('insert into %s (email,entered,confirmed) values("testuser%s",now(),1)', $tables["user"], $prefix . '-' . $i . '@' . $domain);
$result = Sql_query($query, 0);
$userid = Sql_insert_id();
if ($userid) {
$result = Sql_query("replace into {$tables['listuser']} (userid,listid,entered) values({$userid},{$listid},now())");
reset($data);
while (list($key, $val) = each($data)) {
if ($key && $val) {
Sql_query("replace into {$tables['user_attribute']} (attributeid,userid,value) values(" . $key . ",{$userid}," . $val . ")");
}
}
}
}
return 1;
}
示例2: get_systable
function get_systable($s_systable)
{
global $dbhandle;
// get the field names and types
$sql = 'SELECT RDB$RELATION_FIELDS.RDB$FIELD_NAME AS FNAME,' . ' RDB$RELATION_FIELDS.RDB$FIELD_POSITION,' . ' RDB$FIELD_TYPE AS FTYPE,' . ' RDB$FIELD_SUB_TYPE AS STYPE' . ' FROM RDB$RELATION_FIELDS, RDB$FIELDS' . ' WHERE RDB$RELATION_NAME=\'' . $s_systable['table'] . '\'' . ' AND RDB$FIELD_SOURCE=RDB$FIELDS.RDB$FIELD_NAME' . ' ORDER BY RDB$FIELD_POSITION';
$res = fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
$table = array();
while ($row = fbird_fetch_object($res)) {
$type = isset($row->FTYPE) ? $row->FTYPE : NULL;
$stype = isset($row->STYPE) ? $row->STYPE : NULL;
$table[trim($row->FNAME)]['type'] = get_datatype($type, $stype);
}
fbird_free_result($res);
// get the table content
$sql = 'SELECT *' . ' FROM ' . $s_systable['table'];
if ($s_systable['sysdata'] == FALSE) {
$fields = array_keys($table);
$sql .= ' WHERE ' . pos($fields) . " NOT LIKE 'RDB\$%'" . ' AND ' . pos($fields) . " NOT LIKE 'TMP\$%'";
}
// handle the filter
if (!empty($s_systable['ffield']) && in_array($s_systable['ffield'], array_keys($table))) {
$sql .= $s_systable['sysdata'] == TRUE ? ' WHERE ' : ' AND ';
switch ($s_systable['fvalue']) {
case '':
$sql .= $s_systable['ffield'] . ' IS NULL';
break;
case 'BLOB':
if ($table[$s_systable['ffield']]['type'] == 'BLOB') {
$sql .= $s_systable['ffield'] . " IS NOT NULL";
break;
}
default:
$sql .= $s_systable['ffield'] . "='" . $s_systable['fvalue'] . "'";
}
}
if (!empty($s_systable['order'])) {
$sql .= ' ORDER BY ' . $s_systable['order'] . ' ' . $s_systable['dir'];
}
$res = fbird_query($dbhandle, $sql) or ib_error(__FILE__, __LINE__, $sql);
while ($row = fbird_fetch_object($res)) {
foreach (array_keys($table) as $fname) {
if ($row->{$fname} === 0) {
$table[$fname]['col'][] = '0';
} elseif (!isset($row->{$fname}) || empty($row->{$fname})) {
$table[$fname]['col'][] = ' ';
} elseif ($table[$fname]['type'] == 'BLOB') {
$table[$fname]['col'][] = '<i>BLOB</i>';
} else {
$table[$fname]['col'][] = trim($row->{$fname});
}
}
}
fbird_free_result($res);
return $table;
}
示例3: startClass
public function startClass($class, $definition)
{
$string = "<?php\nclass {$class}";
if ($definition['extend']) {
$string .= ' extends ' . pos($definition['extend']);
}
if ($definition['implement']) {
$string .= ' implements ' . implode(',', $definition['implement']);
}
return $string . "{\n";
}
示例4: _oneQuery
protected function _oneQuery($id)
{
$primary = $this->info(self::PRIMARY);
$select = $this->select();
if (is_scalar($id)) {
$id = array(pos($primary) => $id);
}
foreach ($primary as $p) {
$select->where("`{$this->_name}`.`{$p}` = ?", $id);
}
return $select;
}
示例5: show_array
function show_array($array)
{
$output = "";
for (reset($array); $key = key($array), $pos = pos($array); next($array)) {
if (is_array($pos)) {
$output .= "{$key} : <ul>";
$output .= show_array($pos);
$output .= "</ul>";
} else {
$output .= "{$key} = {$pos} <br/>";
}
}
return $output;
}
示例6: tagVariableVar
protected function tagVariableVar(&$token)
{
if (('}' === $this->prevType || T_VARIABLE === $this->prevType) && !in_array($this->penuType, array(T_NEW, T_OBJECT_OPERATOR, T_DOUBLE_COLON))) {
$t =& $this->types;
end($t);
$i = key($t);
if (T_VARIABLE === $this->prevType && '$' !== $this->penuType) {
if ('$this' !== ($a = $this->texts[$i])) {
$this->texts[$i] = $this->varVarLead . $a . $this->varVarTail;
}
} else {
if ('}' === $this->prevType) {
$a = 1;
$b = array($i, 0);
prev($t);
while ($a > 0 && null !== ($i = key($t))) {
if ('{' === $t[$i]) {
--$a;
} else {
if ('}' === $t[$i]) {
++$a;
}
}
prev($t);
}
$b[1] = $i;
if ('$' !== prev($t)) {
return;
}
} else {
$a = $b = 0;
}
do {
} while ('$' === prev($t));
if (in_array(pos($t), array(T_NEW, T_OBJECT_OPERATOR, T_DOUBLE_COLON))) {
return;
}
$a =& $this->texts;
$b && ($a[$b[0]] = $a[$b[1]] = '');
next($t);
$a[key($t)] = $this->varVarLead;
end($t);
$a[key($t)] .= $this->varVarTail;
}
}
}
示例7: pos
/**
* UTF-8 aware alternative to strpos.
*
* Find position of first occurrence of a string.
* This will get alot slower if offset is used.
*
* @see http://www.php.net/strpos
* @see utf8_strlen
* @see utf8_substr
*
* @param string $str haystack
* @param string $needle needle (you should validate this with utf8_is_valid)
* @param integer|false $offset offset in characters (from left)
*
* @return mixed integer position or false on failure
*/
function pos($str, $needle, $offset = false)
{
if ($offset === false) {
$ar = explode($needle, $str, 2);
//if (count($ar) > 1)
if (isset($ar[1])) {
return len($ar[0]);
}
return false;
}
if (!is_int($offset)) {
trigger_error('utf8_strpos: Offset must be an integer', E_USER_ERROR);
return false;
}
$str = sub($str, $offset);
if (($pos = pos($str, $needle)) !== false) {
return $pos + $offset;
}
return false;
}
示例8: write_error
} else {
if ($upload) {
if (!is_writable($dirPath)) {
write_error("Error: cannot write to the specified directory.");
} else {
//if mulltipart mode and there is no file form field in request , then write error
if ($isMultiPart && count($_FILES) <= 0) {
write_error("No chunk for save.");
}
//if can't open file for append , then write error
if (!($file = fopen($filePath, "a"))) {
write_error("Can't open file for write.");
}
//logic to read and save chunk posted with multipart
if ($isMultiPart) {
$filearr = pos($_FILES);
if (!($input = file_get_contents($filearr['tmp_name']))) {
write_error("Can't read from file.");
} else {
if (!fwrite($file, $input)) {
write_error("Can't write to file.");
}
}
} else {
$input = file_get_contents("php://input");
if (!fwrite($file, $input)) {
write_error("Can't write to file.");
}
}
fclose($file);
//Upload complete if size of saved temp file >= size of source file.
示例9: replaceMacroVars
function replaceMacroVars($branch, $vars)
{
$newBranch = array();
foreach ($branch as $leaf) {
if (is_array($leaf)) {
if (pos($leaf) == 'unquote') {
$newBranch[] = $vars[$leaf[1]];
} else {
if (pos($leaf) == 'unquotesplice') {
foreach ($vars[$leaf[1]] as $part) {
$newBranch[] = $part;
}
} else {
$newBranch[] = $this->replaceMacroVars($leaf, $vars);
}
}
} else {
$newBranch[] = $leaf;
}
}
return $newBranch;
}
示例10: replace_symbol
public static function replace_symbol($symbol)
{
$symbol = pos($symbol);
return self::$symbols_hash[$symbol][array_rand(self::$symbols_hash[$symbol])];
}
示例11: getAccessList
function getAccessList($name, $selected = "private")
{
$arr = array("private" => "Private", "public" => "Global public", "group" => "Group public");
if (ereg(",", $selected)) {
$selected = "group";
}
$out = "<select name=\"{$name}\">\n";
for (reset($arr); current($arr); next($arr)) {
$out .= '<option value="' . key($arr) . '"';
if ($selected == key($arr)) {
$out .= " SELECTED";
}
$out .= ">" . pos($arr) . "</option>\n";
}
$out .= "</select>\n";
return $out;
}
示例12: marc_select
function marc_select($type, $name = 'mySelector', $selected = '', $onchange = '')
{
$source = new marc_list($type);
if ($onchange) {
$onchange = " onchange=\"{$onchange}\" ";
}
$this->display = "<select id='{$name}' name='{$name}' {$onchange} >";
if ($selected) {
foreach ($source->table as $value => $libelle) {
if (!($value == $selected)) {
$tag = "<option value='{$value}'>";
} else {
$tag = "<option value='{$value}' selected='selected' >";
}
$this->display .= "{$tag}{$libelle}</option>";
}
} else {
// cirque à cause d'un bug d'IE
reset($source->table);
$this->display .= "<option value='" . key($source->table) . "' selected='selected' >";
$this->display .= pos($source->table) . '</option>';
while (next($source->table)) {
$this->display .= "<option value='" . key($source->table) . "'>";
$this->display .= pos($source->table) . '</option>';
}
}
$this->display .= "</select>";
}
示例13: _saveDbData
/**
* dbFormHandler::_saveData()
*
* Save the data into the database
*
* @param array $data: associative array with the fields => values which should be saved
* @return int: the id which was used to save the record
* @access private
* @author Teye Heimans
*/
function _saveDbData($data)
{
// get the not-null fields from the table
$notNullFields = $this->_db->getNotNullFields($this->_table);
// get the data which should be saved
foreach ($data as $field => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}
// remove unneeded spaces
$value = trim($value);
// do we have to save the field ?
if (!in_array($field, $this->_dontSave) && (!isset($this->_fields[$field]) || !method_exists($this->_fields[$field][1], 'getViewMode') || !$this->_fields[$field][1]->getViewMode())) {
// is the value empty and it can contain NULL, then save NULL
if ($value == '' && !in_array($field, $notNullFields)) {
$value = 'NULL';
$this->_sql[] = $field;
// overwrite the old value with the new one
$data[$field] = $value;
}
} else {
unset($data[$field]);
}
}
// get the column types of the fields
$fields = $this->_db->getFieldTypes($this->_table);
// walk all datefields
foreach ($this->_date as $field) {
// do we still have to convert the value ?
if (isset($data[$field]) && $data[$field] != 'NULL') {
// does the field exists in the table?
if (isset($fields[$field])) {
// get the fields type
$type = strtolower($fields[$field][0]);
// is the field's type a date field ?
if (strpos(strtolower($type), 'date') !== false) {
// get the value from the field
list($y, $m, $d) = $this->_fields[$field][1]->getAsArray();
// are all fields empty ?
if (empty($d) && empty($m) && empty($y)) {
// save NULL if possible, otherwise 0000-00-00
if (in_array($field, $notNullFields)) {
// this field cannot contain NULL
$data[$field] = '0000-00-00';
} else {
$data[$field] = 'NULL';
$this->_sql[] = $field;
}
} else {
// make sure that there are values for each "field"
if ($d == '') {
$d = '00';
}
if ($m == '') {
$m = '00';
}
if ($y == '') {
$y = '0000';
}
//date('Y');
// save the value as date
$data[$field] = $this->_db->dbDate($y, $m, $d);
$this->_sql[] = $field;
}
}
}
}
}
// get the query
$query = $this->_getQuery($this->_table, $data, $this->_sql, $this->edit, $this->_id);
// for debugging.. die when we got the query
//$this->dieOnQuery = true;
if (isset($this->dieOnQuery) && $this->dieOnQuery) {
echo "<pre>";
echo $query;
echo "</pre>";
exit;
}
// make sure that there is something to save...
if (!$query) {
return 0;
}
// execute the query
$sql = $this->_db->query($query);
// query failed?
if (!$sql) {
trigger_error("Error, query failed!<br />\n" . "<b>Error message:</b> " . $this->_db->getError() . "<br />\n" . "<b>Query:</b> " . $query, E_USER_WARNING);
return -1;
} else {
// is it an edit form ? Then return the known edit id's
//.........这里部分代码省略.........
示例14: key
for ($j = 1; $j <= 5; $j++) {
$sql .= 'shoot' . $j;
if ($j < 5) {
$sql .= ' + ';
}
}
$sql .= ' AS total FROM Societe_2016 WHERE id_shooter = ' . key($tab) . ' ORDER BY total DESC LIMIT 0 , 1';
$res = mysql_query($sql) or die('requete invalide');
$n_passe = 1;
//affichage des 3 passe concernée
while ($data = mysql_fetch_array($res)) {
echo ' <strong>Total société:</strong>';
$total_passe = 0;
for ($j = 0; $j <= 5; $j++) {
$sh = 'shoot' . $j;
if (isset($data[$sh])) {
$total_passe += $data[$sh];
}
}
$str = sprintf("%05s", $total_passe);
echo str_replace('0', ' ', substr($str, 0, 3));
echo substr($str, 3, 2);
$n_passe++;
}
echo ' <strong>Total :' . pos($tab) . '</strong>';
echo '</div></div><br />';
next($tab);
}
}
echo '</page>';
mysql_close($base);
示例15: cluster
/**
* Constructor.
*
* @param $clusterdata int/object/array The data id of a data record or data elements to load manually.
*
*/
function cluster($clusterdata = false)
{
global $CURMAN;
parent::datarecord();
$this->set_table(CLSTTABLE);
$this->add_property('id', 'int');
$this->add_property('name', 'string');
$this->add_property('display', 'string');
$this->add_property('leader', 'int');
$this->add_property('parent', 'int');
$this->add_property('depth', 'int');
if (is_numeric($clusterdata)) {
$this->data_load_record($clusterdata);
} else {
if (is_array($clusterdata)) {
$this->data_load_array($clusterdata);
} else {
if (is_object($clusterdata)) {
$this->data_load_array(get_object_vars($clusterdata));
}
}
}
if (!empty($this->id)) {
// custom fields
$level = context_level_base::get_custom_context_level('cluster', 'block_curr_admin');
if ($level) {
$fielddata = field_data::get_for_context(get_context_instance($level, $this->id));
$fielddata = $fielddata ? $fielddata : array();
foreach ($fielddata as $name => $value) {
$this->{"field_{$name}"} = $value;
}
}
}
/*
* profile_field1 -select box
* profile_value1 -select box corresponding to profile_field1
*
* profile_field2 -select box
* profile_value2 -select box corresponding to profile_field2
*/
$prof_fields = $CURMAN->db->get_records(CLSTPROFTABLE, 'clusterid', $this->id, '', '*', 0, 2);
if (!empty($prof_fields)) {
foreach (range(1, 2) as $i) {
$profile = pos($prof_fields);
if (!empty($profile)) {
$field = 'profile_field' . $i;
$value = 'profile_value' . $i;
$this->{$field} = $profile->fieldid;
$this->{$value} = $profile->value;
}
next($prof_fields);
}
}
}