本文整理汇总了PHP中length函数的典型用法代码示例。如果您正苦于以下问题:PHP length函数的具体用法?PHP length怎么用?PHP length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了length函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: widget
function widget($args, $n = '')
{
// $args is an array of strings that help widgets to conform to
// the active theme: before_widget, before_title, after_widget,
// and after_title are the array keys. Default tags: li and h2.
extract($args);
//nb. $name comes out of this, hence the use of $n
global $advman_engine;
//If name not passed in (Sidebar Modules), extract from the widget-id (WordPress Widgets)
if ($n == '') {
$l = length(__('Ad: '));
$n = substr($args['widget_name'], $l);
//Chop off beginning advman- bit
}
if ($n == 'default-ad') {
$n = $advman_engine->getSetting('default-ad');
}
$ad = $advman_engine->selectAd($n);
if (!empty($ad)) {
$widgets = $advman_engine->getSetting('widgets');
$id = substr(md5($ad->name), 0, 10);
$suppress = !empty($widgets[$id]['suppress']);
$ad_widget = '';
$ad_widget .= $suppress ? '' : $before_widget;
if (!empty($widgets[$id]['title'])) {
$ad_widget .= $suppress ? '' : $before_title;
$ad_widget .= $widgets[$id]['title'];
$ad_widget .= $suppress ? '' : $after_title;
}
$ad_widget .= $ad->display();
//Output the selected ad
$ad_widget .= $suppress ? '' : $after_widget;
echo $ad_widget;
}
}
示例2: truncate
public static function truncate($subject, $length, $omission = '...')
{
if (length($subject) > $length) {
$omission_length = length($omission);
$subject = substr($subject, 0, length($subject) - $omission_length);
$subject .= $omission;
}
return $subject;
}
示例3: ends_with
/**
* Determine if a given string ends with a given substring.
*
* @param string $haystack
* @param string|array $needles
*
* @return bool
*/
function ends_with(string $haystack, $needles) : bool
{
foreach ((array) $needles as $needle) {
if ((string) $needle === substr($haystack, -length($needle))) {
return true;
}
}
return false;
}
示例4: length
/**
* Returns the number of elements in a list.
*
* @param Cons $alist a list
*/
function length($alist)
{
if (isNull($alist)) {
return 0;
} elseif (isPair($alist)) {
return 1 + length(cdr($alist));
} else {
throw new \InvalidArgumentException("{$alist} is not a proper list");
}
}
示例5: wfSpecialGeo
/**
*
*/
function wfSpecialGeo($page = '')
{
global $wgOut, $wgLang, $wgRequest;
$coordinates = htmlspecialchars($wgRequest->getText('coordinates'));
$coordinates = explode(":", $coordinates);
$ns = array_shift($coordinates);
$ew = array_shift($coordinates);
if (0 < count($coordinates)) {
$zoom = length(array_shift($coordinates));
} else {
$zoom = 6;
}
$ns = explode(".", $ns);
$ew = explode(".", $ew);
while (count($ns) < 3) {
$ns[] = "0";
}
while (count($ew) < 3) {
$ew[] = "0";
}
$mapquest = "http://www.mapquest.com/maps/map.adp?latlongtype=decimal&latitude={$ns[0]}.{$ns[1]}&longitude={$ew[0]}.{$ew[1]}&zoom={$zoom}";
$mapquest = "<a href=\"{$mapquest}\">Mapquest</a>";
$wgOut->addHTML("{$mapquest}");
/*
if( $wgRequest->getVal( 'action' ) == 'submit') {
$page = $wgRequest->getText( 'pages' );
$curonly = $wgRequest->getCheck( 'curonly' );
} else {
# Pre-check the 'current version only' box in the UI
$curonly = true;
}
if( $page != "" ) {
header( "Content-type: application/xml; charset=utf-8" );
$pages = explode( "\n", $page );
$xml = pages2xml( $pages, $curonly );
echo $xml;
wfAbruptExit();
}
$wgOut->addWikiText( wfMsg( "exporttext" ) );
$titleObj = Title::makeTitle( NS_SPECIAL, "Export" );
$action = $titleObj->escapeLocalURL();
$wgOut->addHTML( "
<form method='post' action=\"$action\">
<input type='hidden' name='action' value='submit' />
<textarea name='pages' cols='40' rows='10'></textarea><br />
<label><input type='checkbox' name='curonly' value='true' checked='checked' />
" . wfMsg( "exportcuronly" ) . "</label><br />
<input type='submit' />
</form>
" );
*/
}
示例6: Perla_strlen
function Perla_strlen($text) {
if (isset($text)) {
return length($text);
}
else
{
return 'Podaj ciąg mający więcej niż 0 znaków!';
}
echo Perla_reverse('perła');
//test
}
示例7: getParentCategory
public function getParentCategory($category_id)
{
if (length($category_id) < 2) {
throw Dolcore_Exception(sprintf(_('Tried to get the parent category of a top category %s'), $category_id));
}
$parent_id = substr($category_id, 0, -1);
$parent = $this->getCategory($parent_id);
if (!$parent) {
throw Dolcore_Exception(sprintf(_('No parent category for child category %s'), $category_id));
}
return $parent;
}
示例8: readbtable
function readbtable($tfile, $genelist, $numgenes)
{
$f = fopen($tfile, "rb");
$out = array();
for ($i = 0; $i < length($genelist); $i++) {
fseek($f, $genelist[$i] * $numgenes - 1);
#from start???
$out[] = fread($f, $numgenes);
#double somehow
}
fclose($f);
return $out;
}
示例9: addItem
public function addItem($vars = array())
{
$cnf = Zend_Registry::get('cnf');
$db = Zend_Db::factory($cnf->db);
$cols = "";
$values = "";
foreach ($vars as $key => $value) {
$coma = length($cols) > 0 ? "," : "";
$cols += $coma + "`{$key}\\`";
$values += $coma + "\\'{$value}\\'";
}
$db->query("INSERT admin_menu ({$cols}) VALUES ({$values})");
}
示例10: checkLastConsonantSoftness
public function checkLastConsonantSoftness($word)
{
if (($substring = last_position_for_one_of_chars(lower($word), array_map(__NAMESPACE__ . '\\lower', self::$consonants))) !== false) {
if (in_array(slice($substring, 0, 1), ['й', 'ч', 'щ'])) {
// always soft consonants
return true;
} else {
if (length($substring) > 1 && in_array(slice($substring, 1, 2), ['е', 'ё', 'и', 'ю', 'я', 'ь'])) {
// consonants are soft if they are trailed with these vowels
return true;
}
}
}
return false;
}
示例11: substr
public static function substr($str, $startPos, $length = 0)
{
if ($startPos < 0) {
$startPos = length($str) + $startPos;
if ($startPos < 0) {
$startPos = length($str);
}
}
preg_match_all("/./u", $str, $array);
if ($length) {
$end = $startPos + $length;
return join("", array_slice($array[0], $start, $end));
} else {
return join("", array_slice($array[0], $start));
}
}
示例12: do
public function do($searchData, $cleanWord)
{
if (length($cleanWord) > length($searchData)) {
throw new LogicException('[Cleaner::data()] -> 3.($cleanWord) parameter not be longer than 2.($searchData) parameter!');
}
if (!is_array($searchData)) {
$result = str_replace($cleanWord, '', $searchData);
} else {
if (!is_array($cleanWord)) {
$cleanWordArray[] = $cleanWord;
} else {
$cleanWordArray = $cleanWord;
}
$result = array_diff($searchData, $cleanWordArray);
}
return $result;
}
示例13: url_upload
function url_upload($url)
{
if ($img_type = $this->check_img_url($url)) {
$content = $this->down_with_curl($url);
} else {
$this->err_msg .= ' !URL изображения не верен ';
return FALSE;
}
if ($content == false && length($content) < 100) {
$this->err_msg .= ' !Изображение не загруженно ';
return FALSE;
}
$img_fname = md5($content) . '.' . $img_type;
file_put_contents($this->img_folder . $img_fname, $content);
$this->file_data = array('file_name' => $img_fname, 'file_path' => $this->img_folder);
return TRUE;
}
示例14: traerCapacitacionMenu
function traerCapacitacionMenu()
{
$db = Conectar();
$sql = "SELECT * FROM capacitacion ORDER BY id_cap DESC";
$resultado = $db->query($sql);
while ($data = $resultado->fetch_object()) {
echo '
<article class="CursosImagenes col" >
<h2><a class="LinkCursos" href="curso_detalle.php?id=' . $data->id_cap . '#aqui" >' . length($data->titulo) . '</a></h2>
<a href="curso_detalle.php?id=' . $data->id_cap . '#aqui" rel="nofollow" >
<div class="ImagenCurso"><img class="SacarSeccionCelular" src="upload/' . $data->imagen . '"/><div class="HoverCursos"><div class="SimboloMas"></div></div></div>
</a>
</article>
';
}
return $resultado;
}
示例15: replaceAll
/**
* Replaces all old string within the expression with new strings.
*
* @param String|\Tbm\Peval\Types\String $expression
* The string being processed.
* @param String|\Tbm\Peval\Types\String $oldString
* The string to replace.
* @param String|\Tbm\Peval\Types\String $newString
* The string to replace the old string with.
*
* @return mixed The new expression with all of the old strings replaced with new
* strings.
*/
public function replaceAll(string $expression, string $oldString, string $newString)
{
$replacedExpression = $expression;
if ($replacedExpression != null) {
$charCtr = 0;
$oldStringIndex = $replacedExpression->indexOf($oldString, $charCtr);
while ($oldStringIndex > -1) {
// Remove the old string from the expression.
$buffer = new StringBuffer($replacedExpression->subString(0, oldStringIndex)->getValue() . $replacedExpression->substring($oldStringIndex + $oldString . length()));
// Insert the new string into the expression.
$buffer . insert($oldStringIndex, $newString);
$replacedExpression = buffer . toString();
$charCtr = $oldStringIndex + $newString->length();
// Determine if we need to continue to search.
if ($charCtr < $replacedExpression->length()) {
$oldStringIndex = $replacedExpression->indexOf($oldString, $charCtr);
} else {
$oldStringIndex = -1;
}
}
}
return $replacedExpression;
}