当前位置: 首页>>代码示例>>PHP>>正文


PHP substr函数代码示例

本文整理汇总了PHP中substr函数的典型用法代码示例。如果您正苦于以下问题:PHP substr函数的具体用法?PHP substr怎么用?PHP substr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了substr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: procesar

 function procesar()
 {
     toba::logger_ws()->debug('Servicio Llamado: ' . $this->info['basica']['item']);
     toba::logger_ws()->set_checkpoint();
     set_error_handler('toba_logger_ws::manejador_errores_recuperables', E_ALL);
     $this->validar_componente();
     //-- Pide los datos para construir el componente, WSF no soporta entregar objetos creados
     $clave = array();
     $clave['proyecto'] = $this->info['objetos'][0]['objeto_proyecto'];
     $clave['componente'] = $this->info['objetos'][0]['objeto'];
     list($tipo, $clase, $datos) = toba_constructor::get_runtime_clase_y_datos($clave, $this->info['objetos'][0]['clase'], false);
     agregar_dir_include_path(toba_dir() . '/php/3ros/wsf');
     $opciones_extension = toba_servicio_web::_get_opciones($this->info['basica']['item'], $clase);
     $wsdl = strpos($_SERVER['REQUEST_URI'], "?wsdl") !== false;
     $sufijo = 'op__';
     $metodos = array();
     $reflexion = new ReflectionClass($clase);
     foreach ($reflexion->getMethods() as $metodo) {
         if (strpos($metodo->name, $sufijo) === 0) {
             $servicio = substr($metodo->name, strlen($sufijo));
             $prefijo = $wsdl ? '' : '_';
             $metodos[$servicio] = $prefijo . $metodo->name;
         }
     }
     $opciones = array();
     $opciones['serviceName'] = $this->info['basica']['item'];
     $opciones['classes'][$clase]['operations'] = $metodos;
     $opciones = array_merge($opciones, $opciones_extension);
     $this->log->debug("Opciones del servidor: " . var_export($opciones, true), 'toba');
     $opciones['classes'][$clase]['args'] = array($datos);
     toba::logger_ws()->set_checkpoint();
     $service = new WSService($opciones);
     $service->reply();
     $this->log->debug("Fin de servicio web", 'toba');
 }
开发者ID:emma5021,项目名称:toba,代码行数:35,代码来源:toba_solicitud_servicio_web.php

示例2: __construct

 /**
  * @param mixed $in
  */
 public function __construct($in = null)
 {
     $fields = array('to', 'cc', 'bcc', 'message', 'body', 'subject');
     if (is_string($in)) {
         if (($pos = strpos($in, '?')) !== false) {
             parse_str(substr($in, $pos + 1), $this->args);
             $this->args['to'] = substr($in, 0, $pos);
         } else {
             $this->args['to'] = $in;
         }
     } elseif ($in instanceof Horde_Variables) {
         foreach ($fields as $val) {
             if (isset($in->{$val})) {
                 $this->args[$val] = $in->{$val};
             }
         }
     } elseif (is_array($in)) {
         $this->args = $in;
     }
     if (isset($this->args['to']) && strpos($this->args['to'], 'mailto:') === 0) {
         $mailto = @parse_url($this->args['to']);
         if (is_array($mailto)) {
             $this->args['to'] = isset($mailto['path']) ? $mailto['path'] : '';
             if (!empty($mailto['query'])) {
                 parse_str($mailto['query'], $vals);
                 foreach ($fields as $val) {
                     if (isset($vals[$val])) {
                         $this->args[$val] = $vals[$val];
                     }
                 }
             }
         }
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:37,代码来源:Link.php

示例3: escapeArgument

 /**
  * Escapes a string to be used as a shell argument.
  *
  * @param string $argument The argument that will be escaped
  *
  * @return string The escaped argument
  */
 public static function escapeArgument($argument)
 {
     //Fix for PHP bug #43784 escapeshellarg removes % from given string
     //Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
     //@see https://bugs.php.net/bug.php?id=43784
     //@see https://bugs.php.net/bug.php?id=49446
     if ('\\' === DIRECTORY_SEPARATOR) {
         if ('' === $argument) {
             return escapeshellarg($argument);
         }
         $escapedArgument = '';
         $quote = false;
         foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
             if ('"' === $part) {
                 $escapedArgument .= '\\"';
             } elseif (self::isSurroundedBy($part, '%')) {
                 // Avoid environment variable expansion
                 $escapedArgument .= '^%"' . substr($part, 1, -1) . '"^%';
             } else {
                 // escape trailing backslash
                 if ('\\' === substr($part, -1)) {
                     $part .= '\\';
                 }
                 $quote = true;
                 $escapedArgument .= $part;
             }
         }
         if ($quote) {
             $escapedArgument = '"' . $escapedArgument . '"';
         }
         return $escapedArgument;
     }
     return escapeshellarg($argument);
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:41,代码来源:ProcessUtils.php

示例4: getAliases

 /**
  * Requests API data and returns aliases
  *
  * @return string
  */
 private function getAliases()
 {
     $request = new Request();
     $user = new User();
     $path = 'drush_aliases';
     $method = 'GET';
     $response = $request->request('users', Session::getValue('user_id'), $path, $method);
     eval(str_replace('<?php', '', $response['data']->drush_aliases));
     $formatted_aliases = substr($response['data']->drush_aliases, 0, -1);
     $sites_object = new Sites();
     $sites = $sites_object->all();
     foreach ($sites as $site) {
         $environments = $site->environments->all();
         foreach ($environments as $environment) {
             $key = $site->get('name') . '.' . $environment->get('id');
             if (isset($aliases[$key])) {
                 break;
             }
             try {
                 $formatted_aliases .= PHP_EOL . "  \$aliases['{$key}'] = ";
                 $formatted_aliases .= $this->constructAlias($environment);
             } catch (TerminusException $e) {
                 continue;
             }
         }
     }
     $formatted_aliases .= PHP_EOL;
     return $formatted_aliases;
 }
开发者ID:pantheon-systems,项目名称:terminus,代码行数:34,代码来源:PantheonAliases.php

示例5: getDatesBetween

 public function getDatesBetween($dStart, $dEnd)
 {
     if ($dStart > $dEnd) {
         $var = $dStart;
         $dStart = $dEnd;
         $dEnd = $var;
     }
     $iStart = strtotime($dStart);
     $iEnd = strtotime($dEnd);
     if (false === $iStart || false === $iEnd) {
         return false;
     }
     $aStart = explode('-', $dStart);
     $aEnd = explode('-', $dEnd);
     if (count($aStart) !== 3 || count($aEnd) !== 3) {
         return false;
     }
     if (false === checkdate($aStart[1], $aStart[2], $aStart[0]) || false === checkdate($aEnd[1], $aEnd[2], $aEnd[0]) || $iEnd < $iStart) {
         return false;
     }
     for ($i = $iStart; $i < $iEnd + 86400; $i = strtotime('+1 day', $i)) {
         $sDateToArr = strftime('%Y-%m-%d', $i);
         $sYear = substr($sDateToArr, 0, 4);
         $sMonth = substr($sDateToArr, 5, 2);
         //$aDates[$sYear][$sMonth][]=$sDateToArr;
         $aDates[] = $sDateToArr;
     }
     if (isset($aDates) && !empty($aDates)) {
         return $aDates;
     } else {
         return false;
     }
 }
开发者ID:NadaNafti,项目名称:Thalassa,代码行数:33,代码来源:Library.php

示例6: isXliff

 public static function isXliff($stringData = null, $fullPathToFile = null)
 {
     self::_reset();
     $info = array();
     if (!empty($stringData) && empty($fullPathToFile)) {
         $stringData = substr($stringData, 0, 1024);
     } elseif (empty($stringData) && !empty($fullPathToFile)) {
         $info = FilesStorage::pathinfo_fix($fullPathToFile);
         $file_pointer = fopen("{$fullPathToFile}", 'r');
         // Checking Requirements (By specs, I know that xliff version is in the first 1KB)
         $stringData = fread($file_pointer, 1024);
         fclose($file_pointer);
     } elseif (!empty($stringData) && !empty($fullPathToFile)) {
         //we want to check extension and content
         $info = FilesStorage::pathinfo_fix($fullPathToFile);
     }
     self::$fileType['info'] = $info;
     //we want to check extension also if file path is specified
     if (!empty($info) && !self::isXliffExtension()) {
         //THIS IS NOT an xliff
         return false;
     }
     //		preg_match( '|<xliff\s.*?version\s?=\s?["\'](.*?)["\'](.*?)>|si', $stringData, $tmp );
     if (!empty($stringData)) {
         return array($stringData);
     }
     return false;
 }
开发者ID:spMohanty,项目名称:MateCat,代码行数:28,代码来源:DetectProprietaryXliff.php

示例7: htmlList

 /**
  * Generates a 'List' element.
  *
  * @param array   $items   Array with the elements of the list
  * @param boolean $ordered Specifies ordered/unordered list; default unordered
  * @param array   $attribs Attributes for the ol/ul tag.
  * @return string The list XHTML.
  */
 public function htmlList(array $items, $ordered = false, $attribs = false, $escape = true)
 {
     if (!is_array($items)) {
         #require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('First param must be an array');
         $e->setView($this->view);
         throw $e;
     }
     $list = '';
     foreach ($items as $item) {
         if (!is_array($item)) {
             if ($escape) {
                 $item = $this->view->escape($item);
             }
             $list .= '<li>' . $item . '</li>' . self::EOL;
         } else {
             if (6 < strlen($list)) {
                 $list = substr($list, 0, strlen($list) - 6) . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
             } else {
                 $list .= '<li>' . $this->htmlList($item, $ordered, $attribs, $escape) . '</li>' . self::EOL;
             }
         }
     }
     if ($attribs) {
         $attribs = $this->_htmlAttribs($attribs);
     } else {
         $attribs = '';
     }
     $tag = 'ul';
     if ($ordered) {
         $tag = 'ol';
     }
     return '<' . $tag . $attribs . '>' . self::EOL . $list . '</' . $tag . '>' . self::EOL;
 }
开发者ID:ravi2jdesign,项目名称:solvingmagento_1.7.0,代码行数:42,代码来源:HtmlList.php

示例8: process

 /**
  * Processes this test, when one of its tokens is encountered.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token in the
  *                                        stack passed in $tokens.
  *
  * @return void
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     // Make sure this is the first PHP open tag so we don't process
     // the same file twice.
     $prevOpenTag = $phpcsFile->findPrevious(T_OPEN_TAG, $stackPtr - 1);
     if ($prevOpenTag !== false) {
         return;
     }
     $fileName = $phpcsFile->getFileName();
     $extension = substr($fileName, strrpos($fileName, '.'));
     $nextClass = $phpcsFile->findNext(array(T_CLASS, T_INTERFACE), $stackPtr);
     if ($extension === '.php') {
         if ($nextClass !== false) {
             $error = '%s found in ".php" file; use ".inc" extension instead';
             $data = array(ucfirst($tokens[$nextClass]['content']));
             $phpcsFile->addError($error, $stackPtr, 'ClassFound', $data);
         }
     } else {
         if ($extension === '.inc') {
             if ($nextClass === false) {
                 $error = 'No interface or class found in ".inc" file; use ".php" extension instead';
                 $phpcsFile->addError($error, $stackPtr, 'NoClass');
             }
         }
     }
 }
开发者ID:CobaltBlueDW,项目名称:oddsandends,代码行数:36,代码来源:FileExtensionSniff.php

示例9: castClosure

 public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     $c = new \ReflectionFunction($c);
     $stub->class = 'Closure';
     // HHVM generates unique class names for closures
     $a = static::castFunctionAbstract($c, $a, $stub, $isNested);
     if (isset($a[$prefix . 'parameters'])) {
         foreach ($a[$prefix . 'parameters'] as &$v) {
             $param = $v;
             $v = array();
             foreach (static::castParameter($param, array(), $stub, true) as $k => $param) {
                 if ("" === $k[0]) {
                     $v[substr($k, 3)] = $param;
                 }
             }
             unset($v['position'], $v['isVariadic'], $v['byReference'], $v);
         }
     }
     if ($f = $c->getFileName()) {
         $a[$prefix . 'file'] = $f;
         $a[$prefix . 'line'] = $c->getStartLine() . ' to ' . $c->getEndLine();
     }
     $prefix = Caster::PREFIX_DYNAMIC;
     unset($a['name'], $a[$prefix . '0'], $a[$prefix . 'this'], $a[$prefix . 'parameter'], $a[Caster::PREFIX_VIRTUAL . 'extra']);
     return $a;
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:27,代码来源:ReflectionCaster.php

示例10: PMA_sanitize

/**
 * Sanitizes $message, taking into account our special codes
 * for formatting.
 *
 * If you want to include result in element attribute, you should escape it.
 *
 * Examples:
 *
 * <p><?php echo PMA_sanitize($foo); ?></p>
 *
 * <a title="<?php echo PMA_sanitize($foo, true); ?>">bar</a>
 *
 * @uses    preg_replace()
 * @uses    strtr()
 * @param   string   the message
 * @param   boolean  whether to escape html in result
 *
 * @return  string   the sanitized message
 *
 * @access  public
 */
function PMA_sanitize($message, $escape = false, $safe = false)
{
    if (!$safe) {
        $message = strtr($message, array('<' => '&lt;', '>' => '&gt;'));
    }
    $replace_pairs = array('[i]' => '<em>', '[/i]' => '</em>', '[em]' => '<em>', '[/em]' => '</em>', '[b]' => '<strong>', '[/b]' => '</strong>', '[strong]' => '<strong>', '[/strong]' => '</strong>', '[tt]' => '<code>', '[/tt]' => '</code>', '[code]' => '<code>', '[/code]' => '</code>', '[kbd]' => '<kbd>', '[/kbd]' => '</kbd>', '[br]' => '<br />', '[/a]' => '</a>', '[sup]' => '<sup>', '[/sup]' => '</sup>');
    $message = strtr($message, $replace_pairs);
    $pattern = '/\\[a@([^"@]*)@([^]"]*)\\]/';
    if (preg_match_all($pattern, $message, $founds, PREG_SET_ORDER)) {
        $valid_links = array('http', './Do', './ur');
        foreach ($founds as $found) {
            // only http... and ./Do... allowed
            if (!in_array(substr($found[1], 0, 4), $valid_links)) {
                return $message;
            }
            // a-z and _ allowed in target
            if (!empty($found[2]) && preg_match('/[^a-z_]+/i', $found[2])) {
                return $message;
            }
        }
        if (substr($found[1], 0, 4) == 'http') {
            $message = preg_replace($pattern, '<a href="' . PMA_linkURL($found[1]) . '" target="\\2">', $message);
        } else {
            $message = preg_replace($pattern, '<a href="\\1" target="\\2">', $message);
        }
    }
    if ($escape) {
        $message = htmlspecialchars($message);
    }
    return $message;
}
开发者ID:dingdong2310,项目名称:g5_theme,代码行数:52,代码来源:sanitizing.lib.php

示例11: __call

 public function __call($s_method_name, $arr_arguments)
 {
     if (!method_exists($this, $s_method_name)) {
         // если еще не имлементировали
         $s_match = "";
         $s_method_prefix = '';
         $s_method_base = '';
         $arr_matches = array();
         $bSucc = preg_match("/[A-Z_]/", $s_method_name, $arr_matches);
         if ($bSucc) {
             $s_match = $arr_matches[0];
             $i_match = strpos($s_method_name, $s_match);
             $s_method_prefix = substr($s_method_name, 0, $i_match) . "/";
             $s_method_base = substr($s_method_name, 0, $i_match + ($s_match === "_" ? 1 : 0));
         }
         $s_class_enter = "__" . $s_method_name;
         // метод, общий для всех режимов
         if (!class_exists($s_class_enter)) {
             $s_entermethod_lib = "methods/" . $s_method_prefix . "__" . $s_method_name . ".lib.php";
             $this->__loadLib($s_entermethod_lib);
             $this->__implement($s_class_enter);
         }
         $s_class_mode = "__" . $s_method_name . "_";
         // метод, выбираемый в зависимости от режима
         if (!class_exists($s_class_mode)) {
             $s_modemethod_lib = "methods/" . $s_method_prefix . "__" . $s_method_name . "_" . cmsController::getInstance()->getCurrentMode() . ".lib.php";
             $this->__loadLib($s_modemethod_lib);
             $this->__implement($s_class_mode);
         }
     }
     return parent::__call($s_method_name, $arr_arguments);
 }
开发者ID:tomoonshine,项目名称:postsms,代码行数:32,代码来源:class+из+content.php

示例12: mb_ord

function mb_ord($char)
{
    $k = mb_convert_encoding($char, 'UCS-2LE', 'UTF-8');
    $k1 = ord(substr($k, 0, 1));
    $k2 = ord(substr($k, 1, 1));
    return $k2 * 256 + $k1;
}
开发者ID:Cazzar,项目名称:Shocky,代码行数:7,代码来源:shocky.php

示例13: wpcom_static_url

 function wpcom_static_url($file)
 {
     $i = hexdec(substr(md5($file), -1)) % 2;
     $http = is_ssl() ? 'https' : 'http';
     $url = $http . '://s' . $i . '.wp.com' . $file;
     return $url;
 }
开发者ID:moscarar,项目名称:cityhow,代码行数:7,代码来源:notes.php

示例14: testChmod

 /**
  *
  */
 public function testChmod()
 {
     $cache = new FileAdapter(self::$dir, new NoneSerializer(), 0777);
     $cache->set('item', 'content');
     $perms = fileperms(self::$dir . '/' . md5('item'));
     $this->assertEquals('0777', substr(sprintf('%o', $perms), -4));
 }
开发者ID:genkgo,项目名称:cache,代码行数:10,代码来源:FileAdapterTest.php

示例15: getLocation

function getLocation($str)
{
    $array_size = intval(substr($str, 0, 1));
    // 拆成的行数
    $code = substr($str, 1);
    // 加密后的串
    $len = strlen($code);
    $subline_size = $len % $array_size;
    // 满字符的行数
    $result = array();
    $deurl = "";
    for ($i = 0; $i < $array_size; $i += 1) {
        if ($i < $subline_size) {
            array_push($result, substr($code, 0, ceil($len / $array_size)));
            $code = substr($code, ceil($len / $array_size));
        } else {
            array_push($result, substr($code, 0, ceil($len / $array_size) - 1));
            $code = substr($code, ceil($len / $array_size) - 1);
        }
    }
    for ($i = 0; $i < ceil($len / $array_size); $i += 1) {
        for ($j = 0; $j < count($result); $j += 1) {
            $deurl = $deurl . "" . substr($result[$j], $i, 1);
        }
    }
    return str_replace("^", "0", urldecode($deurl));
}
开发者ID:surevision,项目名称:node_mpg123_pi,代码行数:27,代码来源:xmu.php


注:本文中的substr函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。