本文整理汇总了PHP中subStr函数的典型用法代码示例。如果您正苦于以下问题:PHP subStr函数的具体用法?PHP subStr怎么用?PHP subStr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了subStr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _gs_utf8_get_map
function _gs_utf8_get_map()
{
$map = array();
$lines = @file(dirName(__FILE__) . '/Translit.txt');
if (!is_array($lines)) {
return $map;
}
foreach ($lines as $line) {
$line = trim($line);
if ($line == '' || subStr($line, 0, 1) == '#') {
continue;
}
$tmp = explode(';', $line, 3);
$char = rTrim(@$tmp[0]);
$translit = trim(@$tmp[1]);
if (!$translit) {
$map[$char] = '';
} else {
$char = hexUnicodeToUtf8($char);
$tmp = @preg_split('/\\s+/S', $translit);
if (!is_array($tmp)) {
continue;
}
$t = '';
foreach ($tmp as $translit) {
$t .= hexUnicodeToUtf8($translit);
}
$map[$char] = $t;
}
}
return $map;
}
开发者ID:rkania,项目名称:GS3,代码行数:32,代码来源:gs_utf_normal.php
示例2: _generate_settings
function _generate_settings($model, $appl, $rtfs, $lnux)
{
global $firmware_url, $firmware_path, $mac, $phone_type, $user;
$file = '';
if (!empty($appl)) {
$file = $model . '-' . $appl . '.bin';
} elseif (!empty($rtfs)) {
$file = $model . '-' . $rtfs;
} elseif (!empty($lnux)) {
$file = $model . '-' . $lnux . '-l.bin';
}
if ($file != '') {
if (subStr($firmware_path, -1) != '/') {
$firmware_path .= '/';
}
$realfile = $firmware_path . $file;
if (!file_exists($realfile) || !is_readable($realfile)) {
# It's important to make sure we don't point the phone to a
# non-existent file or else the phone needs manual interaction
# (something like "File not found. Press any key to continue.")
gs_log(GS_LOG_WARNING, "File \"{$realfile}\" not found");
} else {
$url = $firmware_url . rawUrlEncode($file);
gs_log(GS_LOG_NOTICE, "Snom {$mac} ({$phone_type}, user {$user}): Update file: \"{$file}\"");
//$ob = 'pnp_config$: off' ."\n";
$ob = 'firmware: ' . $url . "\n";
if (!headers_sent()) {
header('Content-Length: ' . strLen($ob));
# avoid chunked transfer-encoding
}
echo $ob;
}
}
exit;
}
开发者ID:rkania,项目名称:GS3,代码行数:35,代码来源:sw-update.php
示例3: get_google_weather
function get_google_weather($city)
{
$url = 'http://www.google.com/ig/api?hl=en&weather=' . $city;
$file = file_get_contents($url);
$file = utf8_encode($file);
$response = simplexml_load_string($file);
$data = array();
# city / state
$tmp = explode(',', $response->weather->forecast_information->city->attributes()->data);
$data['city'] = trim($tmp[0]);
$data['state'] = trim($tmp[1]);
# temperature
$data['temperature'] = $response->weather->current_conditions->temp_c->attributes()->data;
# time
$data['time'] = subStr($response->weather->forecast_information->current_date_time->attributes()->data, 0, 19);
# date
$tmp = explode('-', $response->weather->forecast_information->forecast_date->attributes()->data);
$data['date'] = $tmp[1] . '/' . $tmp[2] . '/' . $tmp[0];
# weather
//$tmp = $response->weather->current_conditions->condition->attributes()->data;
switch ($response->weather->current_conditions->condition->attributes()->data) {
case 'Mostly Cloudy':
$data['weather'] = 'Mostly Cloudy';
break;
case 'Chance of Rain':
$data['weather'] = 'Rain';
break;
case 'Partly Sunny':
$data['weather'] = 'Sunny';
break;
}
return $data;
}
开发者ID:sebastianertz,项目名称:gemeinschaft-grandstream,代码行数:33,代码来源:weather.php
示例4: onOpen
function onOpen() {
$key = $this->getAttribute('key');
$obj = $this->getDocument()->getVariable($key);
if(is_object($obj) || is_array($obj)) {
foreach($obj as $k=>$v) {
$this->getDocument()->setVariable($k, $v);
}
if(is_object($obj)){
// Loop thru each method to detect it's a getter and include its ret value
$rClass = new ReflectionClass($obj);
foreach($rClass->getMethods() as $rMethod){
($mn = $rMethod->getName());
if($rMethod->isPublic()
&& ('get' === substr($mn,0,3))
&& (0 == count($rMethod->getParameters()))) {
$var = subStr($mn,3); //extract the variable name
$var[0] = strToLower($var[0]); //lower first letter case
$this->getDocument()->setVariable($var, $rMethod->invoke($obj) );
}
}
}
return self::PROCESS_BODY;
}
return self::SKIP_BODY;
}
开发者ID:BackupTheBerlios,项目名称:freeform-frmwrk,代码行数:26,代码来源:HTMLShowObject.php5
示例5: conv_ringtone
function conv_ringtone($infile, $outbase)
{
/*
$outfile = $outbase .'.wav';
*/
$outfile = $outbase . '.mp3';
if (strToLower(subStr($infile, -4, 4)) === '.mp3') {
if (fileSize($infile) <= 1000000) {
# 1 MB
if (!@copy($infile, $outfile)) {
return false;
}
return $outfile;
}
}
/*
if (is_executable( '/usr/local/bin/mpg123' ))
$mpg123 = '/usr/local/bin/mpg123';
elseif (is_executable( '/usr/bin/mpg123' ))
$mpg123 = '/usr/bin/mpg123';
elseif (is_executable( '/bin/mpg123' ))
$mpg123 = '/bin/mpg123';
else
$mpg123 = 'mpg123';
if (strToLower(subStr($infile, -4, 4)) === '.mp3') {
# convert mp3 to wav first
$wavfile = $infile .'.wav';
$cmd = $mpg123 .' -m -w - -n 1000 -q '. qsa($infile) .' > '. qsa($wavfile) .' 2>>/dev/null';
# cuts file after 1000 frames (around 2.3 MB, depending on the rate)
# don't use -r 8000 as that doesn't really work for VBR encoded MP3s
@exec($cmd, $out, $err);
if ($err != 0) {
if (is_file($wavfile)) @unlink( $wavfile );
return false;
}
$infile = $wavfile;
$rm_tmp = $wavfile;
} else
$rm_tmp = false;
$cmd = 'sox '. qsa($infile) .' -r 8000 -c 1 -w '. qsa($outfile) .' trim 0 125000s 2>>/dev/null';
# WAV, PCM, 8 kHz, 16 bit, mono
# "The time for loading the file should not be longer then 3 seconds.
# Size < 250 KByte."
# cuts file after 125000 samples (around 245 kB, 15 secs)
@exec($cmd, $out, $err);
if ($err != 0) {
# $err == 2 would be unknown format
if (is_file($outfile)) @unlink( $outfile );
if ($rm_tmp && is_file($rm_tmp)) @unlink($rm_tmp);
return false;
}
return $outfile;
*/
//return false;
return null;
# not implemented
}
开发者ID:philipp-kempgen,项目名称:amooma-gemeinschaft-pbx,代码行数:59,代码来源:capability.php
示例6: setRerunFlag
function setRerunFlag($status)
{
$result = $status;
if (strlen($status) >= 5) {
$result = subStr($status, 0, 3) . '1' . subStr($status, 4, 1);
}
return $result;
}
开发者ID:coderhelps,项目名称:try_samples,代码行数:8,代码来源:num_len.php
示例7: create
/**
* @return \Nano\Route\Common
* @param string $location
* @param string $controller
* @param string $action
* @param string $module
* @param array $params
*/
public static function create($location, $controller = 'index', $action = 'index', $module = null, array $params = array())
{
if ('' === $location || null === $location) {
return new \Nano\Route\StaticLocation($location, $controller, $action, $module, $params);
}
if (self::PREFIX_REGEXP == $location[0]) {
return new \Nano\Route\RegExp(subStr($location, 1), $controller, $action, $module, $params);
}
return new \Nano\Route\StaticLocation($location, $controller, $action, $module, $params);
}
开发者ID:visor,项目名称:nano,代码行数:18,代码来源:Common.php
示例8: formatName
/**
* @return string
* @param string $name
* @param boolean $controller
* @param string|null $module
*/
public static function formatName($name, $controller = true, $module = null)
{
if ($controller) {
return \Nano\Names::controllerClass($name, $module);
}
$result = \Nano::stringToName($name);
$result = strToLower($result[0]) . subStr($result, 1);
$result .= self::SUFFIX_ACTION;
return $result;
}
开发者ID:visor,项目名称:nano,代码行数:16,代码来源:Dispatcher.php
示例9: grandstream_binary_output_checksum
function grandstream_binary_output_checksum($str)
{
$sum = 0;
for ($i = 0; $i <= (strLen($str) - 1) / 2; $i++) {
$sum += ord(subStr($str, 2 * $i, 1)) << 8;
$sum += ord(subStr($str, 2 * $i + 1, 1));
$sum &= 0xffff;
}
$sum = 0x10000 - $sum;
return array($sum >> 8 & 0xff, $sum & 0xff);
}
开发者ID:rkania,项目名称:GS3,代码行数:11,代码来源:grandstream-fns.php
示例10: setView
function setView($viewURI)
{
if (@file_exists($viewURI)) {
$this->view = $viewURI;
} else {
if (APP_VIEWS_LOCATION . $viewURI) {
$this->view = APP_VIEWS_LOCATION . $viewURI;
}
}
$this->type = strToLower(subStr($this->view, strRPos($this->view, ".") + 1));
}
开发者ID:NerdZombies,项目名称:MateCode,代码行数:11,代码来源:View.php
示例11: getObjects
protected function getObjects()
{
/** @var \Pharborist\NodeCollection $objects */
$objects = $this->target->getIndexer($this->configuration['type'])->get($this->configuration['id']);
if (isset($this->configuration['where'])) {
$where = $this->configuration['where'];
// If the first character of the filter is an exclamation point, negate it.
return $where[0] == '!' ? $objects->not(subStr($where, 1)) : $objects->filter($where);
} else {
return $objects;
}
}
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:12,代码来源:NodeCollectorTrait.php
示例12: verifyLCCN
function verifyLCCN()
{
## remove "-" and fill with "0" to make 8 char long
$pos = strPos($lookupVal, "-");
if ($pos > 0) {
$lccnLeft = subStr($lookupVal, 0, $pos);
$lccnRight = subStr($lookupVal, $pos + 1, 6);
$lccnRight = str_pad($lccnRight, 6, "0", STR_PAD_LEFT);
$lookupVal = $lccnLeft . $lccnRight;
}
return $lookupVal;
}
开发者ID:Giordano-Bruno,项目名称:GiordanoBruno,代码行数:12,代码来源:lookupFunc.php
示例13: id
/**
* {@inheritdoc}
*/
public function id()
{
if (empty($this->id)) {
$dir = $this->getBasePath();
$info = (new Finder())->in($dir)->depth('== 0')->name('*.info')->getIterator();
$info->rewind();
if ($info_file = $info->current()) {
$this->id = subStr($info_file->getFilename(), 0, -5);
} else {
throw new \RuntimeException(SafeMarkup::format('Could not find info file in @dir', ['@dir' => $dir]));
}
}
return $this->id;
}
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:17,代码来源:Target.php
示例14: formatName
public static function formatName($name, $controller = true)
{
$result = strToLower($name);
$result = str_replace('-', ' ', $result);
$result = ucWords($result);
$result = str_replace(' ', '', $result);
$result = trim($result);
if ($controller) {
$result .= self::SUFFIX_CONTROLLER;
} else {
$result = strToLower($result[0]) . subStr($result, 1);
$result .= self::SUFFIX_ACTION;
}
return $result;
}
开发者ID:studio-v,项目名称:nano,代码行数:15,代码来源:Dispatcher.php
示例15: find_executable
function find_executable($basename, $paths)
{
if (!is_array($paths)) {
return false;
}
foreach ($paths as $path) {
if (subStr($path, -1) != '/') {
$path .= '/';
}
$full = $path . $basename;
if (is_executable($full)) {
return $full;
}
}
return false;
}
开发者ID:rkania,项目名称:GS3,代码行数:16,代码来源:find_executable.php
示例16: tryLoadClass
/** PSR-0 class loading function */
public function tryLoadClass($className)
{
$toReplace = strpos($className, '\\') === false ? '_' : '\\';
$relativePath = str_replace($toReplace, DIRECTORY_SEPARATOR, $className) . '.php';
foreach ($this->spaceMap as $space => $dir) {
if (subStr($className, 0, strLen($space)) == $space) {
$filePath = $dir . DIRECTORY_SEPARATOR . $relativePath;
//print "<br>\n looking for '$filePath'";
if (file_exists($filePath)) {
//print " FOUND";
include $filePath;
return true;
}
}
}
return false;
}
开发者ID:metaclass-nl,项目名称:fit-shelf,代码行数:18,代码来源:ClassLoader.php
示例17: run
/**
* @return void
* @param string $url
*/
public static function run($url = null)
{
self::instance();
include SETTINGS . DS . 'routes.php';
if (null === $url) {
$url = $_SERVER['REQUEST_URI'];
if (false !== strPos($url, '?')) {
$url = subStr($url, 0, strPos($url, '?'));
}
if (self::config('web')->url && 0 === strPos($url, self::config('web')->url)) {
$url = subStr($url, strLen(self::config('web')->url));
}
if (self::config('web')->index) {
$url = preg_replace('/' . preg_quote(self::config('web')->index) . '$/', '', $url);
}
}
echo self::instance()->dispatcher->dispatch(self::instance()->routes, $url);
}
开发者ID:studio-v,项目名称:nano,代码行数:22,代码来源:Nano.php
示例18: __construct
/**
* Instantiates a new version of the GFPhone object
* @method __construct
* @param string $phoneNumber Phone numnber
*/
function __construct($phoneNumber = "")
{
if ($phoneNumber != "") {
// extract only the digits from the passed value
$this->rawNumber = (string) intval(preg_replace('/[^0-9]+/', '', $phoneNumber), 10);
if (strlen($this->rawNumber) == 10) {
$this->forceRaw = false;
$this->countryCode = 1;
// default to NA
$this->areaCode = substr($this->rawNumber, 0, 3);
$this->prefix = subStr($this->rawNumber, 3, 3);
$this->extension = substr($this->rawNumber, 6, 4);
$this->local = "";
} elseif (strlen($this->rawNumber) == 11) {
$this->forceRaw = false;
$this->countryCode = substr($this->rawNumber, 0, 1);
$this->areaCode = substr($this->rawNumber, 0, 3);
$this->prefix = subStr($this->rawNumber, 3, 3);
$this->extension = substr($this->rawNumber, 6, 4);
$this->local = "";
} elseif (strlen($this->rawNumber) > 11) {
$this->countryCode = substr($this->rawNumber, 0, 1);
$this->areaCode = substr($this->rawNumber, 0, 3);
$this->prefix = subStr($this->rawNumber, 3, 3);
$this->extension = substr($this->rawNumber, 6, 4);
$this->local = substr($this->rawNumber, 10);
} else {
$this->forceRaw = true;
$this->countryCode = "";
$this->areaCode = "";
$this->prefix = "";
$this->extension = "";
$this->local = "";
}
} else {
$this->forceRaw = true;
$this->rawNumber = $phoneNumber;
$this->countryCode = "";
$this->areaCode = "";
$this->prefix = "";
$this->extension = "";
}
}
开发者ID:geniusfactor,项目名称:fibr,代码行数:48,代码来源:GFPhone.php
示例19: test_mod_ratingallocate_generated_module
public function test_mod_ratingallocate_generated_module()
{
$record = mod_ratingallocate_generator::get_default_values();
foreach ($record as $name => $value) {
if (subStr($name, strlen($name) - 7, 7) === 'maxsize') {
$record[$name] = 10;
}
if (subStr($name, strlen($name) - 6, 6) === 'active') {
$record[$name] = true;
}
}
$record['num_students'] = 22;
$test_module = new mod_ratingallocate_generated_module($this, $record);
$this->assertCount($record['num_students'], $test_module->students);
$this->assertCount(20, $test_module->allocations);
$ratingallocate = mod_ratingallocate_generator::get_ratingallocate_for_user($this, $test_module->mod_db, $test_module->teacher);
foreach ($ratingallocate->get_choices_with_allocationcount() as $choice) {
$this->assertEquals(10, $choice->{'usercount'});
}
}
开发者ID:andrewhancox,项目名称:moodle-mod_ratingallocate,代码行数:20,代码来源:mod_generator_test.php
示例20: getButtonValHack
function getButtonValHack()
{
if (!array_key_exists('whichform', $_REQUEST)) {
return null;
}
$whichform = $_REQUEST['whichform'];
$buttonval_key = 'buttonval';
if ($whichform == 4) {
if (array_key_exists('buttonval4a', $_REQUEST)) {
$buttonval_key = 'buttonval4a';
} elseif (array_key_exists('buttonval4b', $_REQUEST)) {
$buttonval_key = 'buttonval4b';
}
}
if (array_key_exists($buttonval_key, $_REQUEST) && subStr($_REQUEST[$buttonval_key], 0, 5) === 'test-') {
return $_REQUEST[$buttonval_key];
} elseif (array_key_exists($buttonval_key, $_REQUEST) && preg_match('/test-[0-9a-z]+/', $_REQUEST[$buttonval_key], $m)) {
return $m[0];
}
}
开发者ID:rkania,项目名称:GS3,代码行数:20,代码来源:button-test.php
注:本文中的subStr函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论