本文整理汇总了PHP中strtok函数的典型用法代码示例。如果您正苦于以下问题:PHP strtok函数的具体用法?PHP strtok怎么用?PHP strtok使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strtok函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
}
}
示例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;
}
示例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}";
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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 () {
};
}