本文整理汇总了PHP中strtok函数的典型用法代码示例。如果您正苦于以下问题:PHP strtok函数的具体用法?PHP strtok怎么用?PHP strtok使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strtok函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: GetMime
/**
* Gets the mime type for a blob
*
* @param GitPHP_Blob $blob blob
* @return string mime type
*/
public function GetMime($blob)
{
if (!$blob) {
return false;
}
$data = $blob->GetData();
if (empty($data)) {
return false;
}
$descspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'));
$proc = proc_open('file -b --mime -', $descspec, $pipes);
if (is_resource($proc)) {
fwrite($pipes[0], $data);
fclose($pipes[0]);
$mime = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($proc);
if ($mime && strpos($mime, '/')) {
if (strpos($mime, ';')) {
$mime = strtok($mime, ';');
}
return $mime;
}
}
return false;
}
开发者ID:fboender,项目名称:gitphp,代码行数:32,代码来源:FileMimeType_FileExe.class.php
示例2: truncate
/**
* Truncates a string to the given length. It will optionally preserve
* HTML tags if $is_html is set to true.
*
* @param string $string the string to truncate
* @param int $limit the number of characters to truncate too
* @param string $continuation the string to use to denote it was truncated
* @param bool $is_html whether the string has HTML
* @return string the truncated string
*/
public static function truncate($string, $limit, $continuation = '...', $is_html = false)
{
$offset = 0;
$tags = array();
if ($is_html) {
// Handle special characters.
preg_match_all('/&[a-z]+;/i', strip_tags($string), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
foreach ($matches as $match) {
if ($match[0][1] >= $limit) {
break;
}
$limit += static::length($match[0][0]) - 1;
}
// Handle all the html tags.
preg_match_all('/<[^>]+>([^<]*)/', $string, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
foreach ($matches as $match) {
if ($match[0][1] - $offset >= $limit) {
break;
}
$tag = static::sub(strtok($match[0][0], " \t\n\r\v>"), 1);
if ($tag[0] != '/') {
$tags[] = $tag;
} elseif (end($tags) == static::sub($tag, 1)) {
array_pop($tags);
}
$offset += $match[1][1] - $match[0][1];
}
}
$new_string = static::sub($string, 0, $limit = min(static::length($string), $limit + $offset));
$new_string .= static::length($string) > $limit ? $continuation : '';
$new_string .= count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : '';
return $new_string;
}
开发者ID:huglester,项目名称:pyrocms-helpers,代码行数:43,代码来源:Str.php
示例3: preXml
function preXml($xml)
{
$xml = preg_replace('/(>)(<)(\\/*)/', "\$1\n\$2\$3", $xml);
$token = strtok($xml, "\n");
$result = '';
// holds formatted version as it is built
$pad = 0;
// initial indent
$matches = array();
// returns from preg_matches()
while ($token !== false) {
if (preg_match('/.+<\\/\\w[^>]*>$/', $token, $matches)) {
$indent = 0;
} elseif (preg_match('/^<\\/\\w/', $token, $matches)) {
$pad -= 4;
} elseif (preg_match('/^<\\w[^>]*[^\\/]>.*$/', $token, $matches)) {
$indent = 4;
} else {
$indent = 0;
}
$line = str_pad($token, strlen($token) + $pad, ' ', STR_PAD_LEFT);
$result .= $line . "\n";
$token = strtok("\n");
$pad += $indent;
}
return htmlspecialchars($result);
}
开发者ID:yogesh-patel,项目名称:js-soap-proxy,代码行数:27,代码来源:formatxml.php
示例4: createLinks
public function createLinks()
{
$pager = $this->_getPager();
$numPages = count($pager->getPages());
$headBlock = Mage::app()->getLayout()->getBlock('head');
$previousPageUrl = $pager->getPreviousPageUrl();
$nextPageUrl = $pager->getNextPageUrl();
if (Mage::helper('mstcore')->isModuleInstalled('Amasty_Shopby')) {
$url = Mage::helper('core/url')->getCurrentUrl();
$url = strtok($url, '?');
$previousPageUrl = $url . '?p=' . ($pager->getCurrentPage() - 1);
$nextPageUrl = $url . '?p=' . ($pager->getCurrentPage() + 1);
if ($pager->getCurrentPage() == 2) {
$previousPageUrl = $url;
}
}
//we have html_entity_decode because somehow manento encodes '&'
if (!$pager->isFirstPage() && !$pager->isLastPage() && $numPages > 2) {
$headBlock->addLinkRel('prev', html_entity_decode($previousPageUrl));
$headBlock->addLinkRel('next', html_entity_decode($nextPageUrl));
} elseif ($pager->isFirstPage() && $numPages > 1) {
$headBlock->addLinkRel('next', html_entity_decode($nextPageUrl));
} elseif ($pager->isLastPage() && $numPages > 1) {
$headBlock->addLinkRel('prev', html_entity_decode($previousPageUrl));
}
return $this;
}
开发者ID:technomagegithub,项目名称:olgo.nl,代码行数:27,代码来源:Paging.php
示例5: postfilter_abbr
function postfilter_abbr($formatter, $value, $options)
{
global $DBInfo;
$abbrs = array();
if (!$DBInfo->local_abbr or !$DBInfo->hasPage($DBInfo->local_abbr)) {
return $value;
}
$p = $DBInfo->getPage($DBInfo->local_abbr);
$raw = $p->get_raw_body();
$lines = explode("\n", $raw);
foreach ($lines as $line) {
$line = trim($line);
if ($line[0] == '#' or $line == '') {
continue;
}
$word = strtok($line, ' ');
$abbrs[$word] = strtok('');
}
$dict = new SimpleDict($abbrs);
$rule = implode('|', array_keys($abbrs));
$chunks = preg_split('/(<[^>]*>)/', $value, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 0, $sz = count($chunks); $i < $sz; $i++) {
if ($chunks[$i][0] == '<') {
continue;
}
$dumm = preg_replace_callback('/\\b(' . $rule . ')\\b/', array($dict, 'get'), $chunks[$i]);
$chunks[$i] = $dumm;
}
return implode('', $chunks);
}
开发者ID:ahastudio,项目名称:moniwiki,代码行数:30,代码来源:abbr.php
示例6: get_current_url
function get_current_url($no_query_params = false)
{
global $post;
$um_get_option = get_option('um_options');
$server_name_method = $um_get_option['current_url_method'] ? $um_get_option['current_url_method'] : 'SERVER_NAME';
$um_port_forwarding_url = isset($um_get_option['um_port_forwarding_url']) ? $um_get_option['um_port_forwarding_url'] : '';
if (!isset($_SERVER['SERVER_NAME'])) {
return '';
}
if (is_front_page()) {
$page_url = home_url();
if (isset($_SERVER['QUERY_STRING']) && trim($_SERVER['QUERY_STRING'])) {
$page_url .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
$page_url = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$page_url .= "s";
}
$page_url .= "://";
if ($um_port_forwarding_url == 1 && isset($_SERVER["SERVER_PORT"])) {
$page_url .= $_SERVER[$server_name_method] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$page_url .= $_SERVER[$server_name_method] . $_SERVER["REQUEST_URI"];
}
}
if ($no_query_params == true) {
$page_url = strtok($page_url, '?');
}
return apply_filters('um_get_current_page_url', $page_url);
}
开发者ID:shramee,项目名称:ultimatemember,代码行数:31,代码来源:um-permalinks.php
示例7: PMA_transformation_getOptions
/**
* Set of functions used with the relation and pdf feature
*/
function PMA_transformation_getOptions($string)
{
$transform_options = array();
/* Parse options */
for ($nextToken = strtok($string, ','); $nextToken !== false; $nextToken = strtok(',')) {
$trimmed = trim($nextToken);
if ($trimmed[0] == '\'' && $trimmed[strlen($trimmed) - 1] == '\'') {
$transform_options[] = substr($trimmed, 1, -1);
} else {
if ($trimmed[0] == '\'') {
$trimmed = ltrim($nextToken);
while ($nextToken !== false) {
$nextToken = strtok(',');
$trimmed .= $nextToken;
$rtrimmed = rtrim($trimmed);
if ($rtrimmed[strlen($rtrimmed) - 1] == '\'') {
break;
}
}
$transform_options[] = substr($rtrimmed, 1, -1);
} else {
$transform_options[] = $nextToken;
}
}
}
// strip possible slashes to behave like documentation says
$result = array();
foreach ($transform_options as $val) {
$result[] = stripslashes($val);
}
return $result;
}
开发者ID:johangas,项目名称:moped,代码行数:35,代码来源:transformations.lib.php
示例8: mappedOutputHelper
/**
* Tests the mapping of fields.
*
* @param \Drupal\views\ViewExecutable $view
* The view to test.
*
* @return string
* The view rendered as HTML.
*/
protected function mappedOutputHelper($view)
{
$output = $view->preview();
$rendered_output = \Drupal::service('renderer')->renderRoot($output);
$this->storeViewPreview($rendered_output);
$rows = $this->elements->body->div->div->div;
$data_set = $this->dataSet();
$count = 0;
foreach ($rows as $row) {
$attributes = $row->attributes();
$class = (string) $attributes['class'][0];
$this->assertTrue(strpos($class, 'views-row-mapping-test') !== FALSE, 'Make sure that each row has the correct CSS class.');
foreach ($row->div as $field) {
// Split up the field-level class, the first part is the mapping name
// and the second is the field ID.
$field_attributes = $field->attributes();
$name = strtok((string) $field_attributes['class'][0], '-');
$field_id = strtok('-');
// The expected result is the mapping name and the field value,
// separated by ':'.
$expected_result = $name . ':' . $data_set[$count][$field_id];
$actual_result = (string) $field;
$this->assertIdentical($expected_result, $actual_result, format_string('The fields were mapped successfully: %name => %field_id', array('%name' => $name, '%field_id' => $field_id)));
}
$count++;
}
return $rendered_output;
}
开发者ID:nsp15,项目名称:Drupal8,代码行数:37,代码来源:StyleMappingTest.php
示例9: writeDbDeleteCheck
function writeDbDeleteCheck($sql)
{
if (getUserConfig('dbsynchron') != "") {
//check for delete items to play on sync
if (substr($sql, 0, 12) == "delete from ") {
$table = trim(strtok(substr($sql, 12), " "));
if ($table != "junk_items") {
$where = strtok(" ");
$where = strtok("");
$del = create_db_connection();
$del->openselect("select id from " . $table . " where " . $where);
$delids = "";
while (!$del->eof()) {
if ($delids != "") {
$delids .= ",";
}
$delids .= $del->getvalue("id");
$del->movenext();
}
$del = create_db_connection();
$del->addnew("junk_items");
$del->setvalue("fromtable", $table);
$del->setvalue("delid", $delids);
$del->setvalue("operation", 3);
$del->update();
}
}
}
}
开发者ID:jawedkhan,项目名称:rorca,代码行数:29,代码来源:db.php
示例10: strtok
function &tree($treeStr)
{
$treeTok = strtok($treeStr, ", ");
if (!$treeTok || $treeTok == "#") {
return array();
}
$root = treeNode($treeTok, null);
$result = array(&$root);
$queue = array(&$root);
while (count($queue) != 0) {
$parent =& $queue[0];
array_shift($queue);
$treeTok = strtok(", ");
if ($treeTok && $treeTok != "#") {
unset($node);
$node = treeNode($treeTok, $parent["name"]);
$queue[] =& $node;
$parent["children"][] =& $node;
}
$treeTok = strtok(", ");
if ($treeTok && $treeTok != "#") {
unset($node);
$node = treeNode($treeTok, $parent["name"]);
$queue[] =& $node;
$parent["children"][] =& $node;
}
}
return $result;
}
开发者ID:raspberrypi360,项目名称:web_games,代码行数:29,代码来源:common.php
示例11: modifyCollate
/**
* Get the SQL for a "comment" column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyCollate(IlluminateBlueprint $blueprint, Fluent $column)
{
if (!is_null($column->collate)) {
$characterSet = strtok($column->collate, '_');
return " character set {$characterSet} collate {$column->collate}";
}
}
开发者ID:joaogl,项目名称:support,代码行数:14,代码来源:MySqlGrammar.php
示例12: current_path
/**
* The requested URL path.
*
* @return string
*/
function current_path()
{
static $path;
if (isset($path)) {
return $path;
}
if (isset($_SERVER['REQUEST_URI'])) {
// This request is either a clean URL, or 'index.php', or nonsense.
// Extract the path from REQUEST_URI.
$request_path = strtok($_SERVER['REQUEST_URI'], '?');
$base_path_len = strlen(rtrim(dirname($_SERVER['SCRIPT_NAME']), '\\/'));
// Unescape and strip $base_path prefix, leaving q without a leading slash.
$path = substr(urldecode($request_path), $base_path_len + 1);
// If the path equals the script filename, either because 'index.php' was
// explicitly provided in the URL, or because the server added it to
// $_SERVER['REQUEST_URI'] even when it wasn't provided in the URL (some
// versions of Microsoft IIS do this), the front page should be served.
if ($path == basename($_SERVER['PHP_SELF'])) {
$path = '';
}
} else {
// This is the front page.
$path = '';
}
// Under certain conditions Apache's RewriteRule directive prepends the value
// assigned to $_GET['q'] with a slash. Moreover we can always have a trailing
// slash in place, hence we need to normalize $_GET['q'].
$path = trim($path, '/');
return $path;
}
开发者ID:RamboLau,项目名称:yaf.framework,代码行数:35,代码来源:Functions.php
示例13: get_ip
/**
* функция определяет ip адрес по глобальному массиву $_SERVER
* ip адреса проверяются начиная с приоритетного, для определения возможного использования прокси
* @return ip-адрес
*/
protected function get_ip()
{
$ip = false;
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipa[] = trim(strtok($_SERVER['HTTP_X_FORWARDED_FOR'], ','));
}
if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ipa[] = $_SERVER['HTTP_CLIENT_IP'];
}
if (isset($_SERVER['REMOTE_ADDR'])) {
$ipa[] = $_SERVER['REMOTE_ADDR'];
}
if (isset($_SERVER['HTTP_X_REAL_IP'])) {
$ipa[] = $_SERVER['HTTP_X_REAL_IP'];
}
// проверяем ip-адреса на валидность начиная с приоритетного.
foreach ($ipa as $ips) {
// если ip валидный обрываем цикл, назначаем ip адрес и возвращаем его
if ($this->is_valid_ip($ips)) {
$ip = $ips;
break;
}
}
return $ip;
}
开发者ID:buildshop,项目名称:bs-common,代码行数:30,代码来源:LALogRoute.php
示例14: tie_vedio
function tie_vedio()
{
global $post, $tie_blog;
$get_meta = get_post_custom($post->ID);
if (!empty($get_meta["tie_video_self_url"][0])) {
echo do_shortcode('[video src="' . $get_meta["tie_video_self_url"][0] . '"][/video]');
} elseif (isset($get_meta["tie_video_url"][0]) && !empty($get_meta["tie_video_url"][0])) {
$video_url = $get_meta["tie_video_url"][0];
$video_link = @parse_url($video_url);
if ($video_link['host'] == 'www.youtube.com' || $video_link['host'] == 'youtube.com') {
parse_str(@parse_url($video_url, PHP_URL_QUERY), $my_array_of_vars);
$video = $my_array_of_vars['v'];
$video_code = '<iframe width="600" height="325" src="http://www.youtube.com/embed/' . $video . '?rel=0&wmode=opaque" frameborder="0" allowfullscreen></iframe>';
} elseif ($video_link['host'] == 'www.vimeo.com' || $video_link['host'] == 'vimeo.com') {
$video = (int) substr(@parse_url($video_url, PHP_URL_PATH), 1);
$video_code = '<iframe width="600" height="325" src="http://player.vimeo.com/video/' . $video . '" width="' . $width . '" height="' . $height . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
} elseif ($video_link['host'] == 'www.youtu.be' || $video_link['host'] == 'youtu.be') {
$video = substr(@parse_url($video_url, PHP_URL_PATH), 1);
$video_code = '<iframe width="600" height="325" src="http://www.youtube.com/embed/' . $video . '?rel=0" frameborder="0" allowfullscreen></iframe>';
} elseif ($video_link['host'] == 'www.dailymotion.com' || $video_link['host'] == 'dailymotion.com') {
$video = substr(@parse_url($video_url, PHP_URL_PATH), 7);
$video_id = strtok($video, '_');
$video_code = '<iframe frameborder="0" width="600" height="325" src="http://www.dailymotion.com/embed/video/' . $video_id . '"></iframe>';
}
} elseif (isset($get_meta["tie_embed_code"][0])) {
$embed_code = $get_meta["tie_embed_code"][0];
$video_code = htmlspecialchars_decode($embed_code);
}
if (isset($video_code)) {
echo $video_code;
}
}
开发者ID:proj-2014,项目名称:vlan247-test-wp,代码行数:32,代码来源:theme-functions.php
示例15: SampleFunction
public function SampleFunction($a, $b = NULL)
{
if ($a === $b) {
bar();
} elseif ($a > $b) {
$foo->bar($arg1);
} else {
BazClass::bar($arg2, $arg3);
}
if (!$b) {
echo $c;
}
if (!strtok($b)) {
echo $d;
}
if (!isset($b)) {
echo $d;
}
if (!($var === $b)) {
echo $c;
}
$variable_name = 'foo';
$_fn = function () {
};
}
开发者ID:ElvenSpellmaker,项目名称:PhpSnifferRules,代码行数:25,代码来源:Test.php
示例16: JDtoYMD
function JDtoYMD($date, &$year, &$month, &$day)
{
$string = JDToGregorian($date);
$month = strtok($string, " -/");
$day = strtok(" -/");
$year = strtok(" -/");
}
开发者ID:rohmad-st,项目名称:fpdf,代码行数:7,代码来源:pdfUSACalendar.php
示例17: phpwhois_cidr_conv
function phpwhois_cidr_conv($net)
{
$start = strtok($net, '/');
$n = 3 - substr_count($net, '.');
if ($n > 0) {
for ($i = $n; $i > 0; $i--) {
$start .= '.0';
}
}
$bits1 = str_pad(decbin(ip2long($start)), 32, '0', 'STR_PAD_LEFT');
$net = pow(2, 32 - substr(strstr($net, '/'), 1)) - 1;
$bits2 = str_pad(decbin($net), 32, '0', 'STR_PAD_LEFT');
$final = '';
for ($i = 0; $i < 32; $i++) {
if ($bits1[$i] == $bits2[$i]) {
$final .= $bits1[$i];
}
if ($bits1[$i] == 1 and $bits2[$i] == 0) {
$final .= $bits1[$i];
}
if ($bits1[$i] == 0 and $bits2[$i] == 1) {
$final .= $bits2[$i];
}
}
return $start . " - " . long2ip(bindec($final));
}
开发者ID:davidegiunchidiennea,项目名称:all-in-one-wordpress-security,代码行数:26,代码来源:whois.ip.lib.php
示例18: strip_attributes_recursive
private static function strip_attributes_recursive($node, $bad_attributes, $bad_protocols)
{
if ($node->nodeType !== XML_ELEMENT_NODE) {
return;
}
if ($node->hasAttributes()) {
foreach ($node->attributes as $attribute) {
$attribute_name = strtolower($attribute->name);
if (in_array($attribute_name, $bad_attributes)) {
$node->removeAttribute($attribute_name);
continue;
}
// on* attributes (like onclick) are a special case
if (0 === stripos($attribute_name, 'on')) {
$node->removeAttribute($attribute_name);
continue;
}
if ('href' === $attribute_name) {
$protocol = strtok($attribute->value, ':');
if (in_array($protocol, $bad_protocols)) {
$node->removeAttribute($attribute_name);
continue;
}
}
}
}
foreach ($node->childNodes as $child_node) {
self::strip_attributes_recursive($child_node, $bad_attributes, $bad_protocols);
}
}
开发者ID:Zaanmedia,项目名称:amp-wp,代码行数:30,代码来源:class-amp-sanitizer.php
示例19: ewiki_auth_query_http
function ewiki_auth_query_http(&$data, $force_query = 0)
{
global $ewiki_plugins, $ewiki_errmsg, $ewiki_author, $ewiki_ring;
#-- fetch user:password
if ($uu = trim($_SERVER["HTTP_AUTHORIZATION"])) {
$auth_method = strtolower(strtok($uu, " "));
if ($auth_method == "basic") {
$uu = strtok(" ;,");
$uu = base64_decode($uu);
list($_a_u, $_a_p) = explode(":", $uu, 2);
} else {
#-- invalid response, ignore
}
} elseif (strlen($_a_u = trim($_SERVER["PHP_AUTH_USER"]))) {
$_a_p = trim($_SERVER["PHP_AUTH_PW"]);
}
#-- check password
$_success = ewiki_auth_user($_a_u, $_a_p);
#-- request HTTP Basic authentication otherwise
if (!$_success && $force_query || $force_query >= 2) {
$realm = ewiki_t("RESTRICTED_ACCESS");
$addmethod = "";
if ($uu = $ewiki_config["login_notice"]) {
$realm .= " " . $uu;
}
if ($uu = $ewiki_config["http_auth_add"]) {
$addmethod = ", {$uu} realm=\"{$realm}\"";
}
header('HTTP/1.1 401 Authentication Required');
header('Status: 401 Authentication Required');
header('WWW-Authenticate: Basic realm="' . $realm . '"' . $addmethod);
}
#-- fin
return $_success;
}
开发者ID:gpuenteallott,项目名称:rox,代码行数:35,代码来源:auth_method_http.php
示例20: docs
/**
* generate docs
*/
public function docs()
{
$docs = [];
foreach (get_declared_classes() as $task) {
if (!preg_match('~Robo\\\\Task.*?Task$~', $task)) {
continue;
}
$docs[basename((new ReflectionClass($task))->getFileName(), '.php')][] = $task;
}
ksort($docs);
$taskGenerator = $this->taskGenDoc('docs/tasks.md')->filterClasses(function (\ReflectionClass $r) {
return !$r->isAbstract() or $r->isTrait();
})->prepend("# Tasks");
foreach ($docs as $file => $classes) {
$taskGenerator->docClass("Robo\\Task\\{$file}");
foreach ($classes as $task) {
$taskGenerator->docClass($task);
}
}
$taskGenerator->filterMethods(function (\ReflectionMethod $m) {
if ($m->isConstructor() or $m->isDestructor() or $m->isStatic()) {
return false;
}
return !in_array($m->name, ['run', '', '__call', 'getCommand']) and $m->isPublic();
// methods are not documented
})->processClassSignature(function ($c) {
return "## " . preg_replace('~Task$~', '', $c->getShortName()) . "\n";
})->processClassDocBlock(function ($c, $doc) {
return preg_replace('~@method .*?\\wTask (.*?)\\)~', '* `$1)` ', $doc);
})->processMethodSignature(function (\ReflectionMethod $m, $text) {
return str_replace('#### *public* ', '* `', $text) . '`';
})->processMethodDocBlock(function (\ReflectionMethod $m, $text) {
return $text ? ' ' . strtok($text, "\n") : '';
})->run();
}
开发者ID:sliver,项目名称:Robo,代码行数:38,代码来源:RoboFile.php
注:本文中的strtok函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论