本文整理汇总了PHP中Nette\String::startsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP String::startsWith方法的具体用法?PHP String::startsWith怎么用?PHP String::startsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\String
的用法示例。
在下文中一共展示了String::startsWith方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDestinationArticle
public function getDestinationArticle($destination)
{
$destination = $this->canonicalizeDestination($destination);
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($c, CURLOPT_USERAGENT, 'Travelbot 1.0 beta');
curl_setopt($c, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($c, CURLOPT_MAXREDIRS, 100);
// using Nette\Web\Uri for escaping GET parameters
$uri = new Uri('http://en.wikipedia.org/w/index.php');
$uri->setQuery(array('title' => $destination));
curl_setopt($c, CURLOPT_URL, (string) $uri);
$result = curl_exec($c);
curl_close($c);
// getting first related paragraph
$correct = FALSE;
$pos = -3;
$i = 0;
while (!$correct && $i < 5) {
$pos = mb_strpos($result, '<p>', $pos + 3, 'UTF-8');
$cropped = mb_substr($result, $pos);
$paragraph = mb_substr($cropped, 0, mb_strpos($cropped, '</p>') + 4);
if (String::startsWith(strip_tags($paragraph), $destination)) {
$paragraph = str_replace('/wiki', 'http://en.wikipedia.org/wiki', $paragraph);
return $paragraph . '<p><a href="' . (string) $uri . '">(more)</a></p>';
}
$i++;
}
throw new ArticleException('Invalid text.');
}
示例2: processArguments
public function processArguments($args, IContext $context)
{
return array_map(function ($arg) use($context) {
if (!is_string($arg)) {
return $arg;
} elseif (String::startsWith($arg, "%")) {
return $context->getService(substr($arg, 1));
} elseif (String::startsWith($arg, "\$\$")) {
return Environment::getConfig(substr($arg, 2));
} elseif (String::startsWith($arg, "\$")) {
return Environment::getVariable(substr($arg, 1));
} else {
return $arg;
}
}, $args);
}
示例3: netteLink
/**
* @param TexyHandlerInvocation handler invocation
* @param string
* @param string
* @param TexyModifier
* @param TexyLink
* @return TexyHtml|string|FALSE
*/
public function netteLink($invocation, $phrase, $content, $modifier, $link)
{
// is there link?
if (!$link) {
return $invocation->proceed();
}
$url = $link->URL;
if (String::startsWith($url, "plink://")) {
$url = substr($url, 8);
list($presenter, $params) = explode("?", $url, 2);
$arr = array();
if ($params) {
parse_str($params, $arr);
}
$link->URL = Environment::getApplication()->getPresenter()->link($presenter, $arr);
}
return $invocation->proceed();
}
示例4: absolutizeUrl
/**
* Make relative url absolute
* @param string image url
* @param string single or double quote
* @param string absolute css file path
* @param string source path
* @return string
*/
public static function absolutizeUrl($url, $quote, $cssFile, $sourcePath)
{
// is already absolute
if (preg_match("/^([a-z]+:\\/)?\\//", $url)) {
return $url;
}
$docroot = realpath(WWW_DIR);
$basePath = rtrim(Environment::getVariable("baseUri"), '/');
// inside document root
if (String::startsWith($cssFile, $docroot)) {
$path = $basePath . substr(dirname($cssFile), strlen($docroot)) . DIRECTORY_SEPARATOR . $url;
// outside document root
} else {
$path = $basePath . substr($sourcePath, strlen($docroot)) . DIRECTORY_SEPARATOR . $url;
}
//$path = self::cannonicalizePath($path);
$path = strtr($path, "\\", "/");
return $quote === '"' ? addslashes($path) : $path;
}
示例5: setUrl
public function setUrl($url)
{
$uriScript = new UriScript($url);
$uriScript->setScriptPath(Environment::getHttpRequest()->getUri()->getScriptPath());
$httpRequest = new HttpRequest($uriScript);
$presenterRequest = Environment::getApplication()->getRouter()->match($httpRequest);
if ($presenterRequest === null || !String::startsWith($url, Environment::getVariable("baseUri"))) {
$this->url = $url ?: null;
$this->destination = null;
$this->params = array();
} else {
$presenter = $presenterRequest->getPresenterName();
$params = $presenterRequest->getParams();
$action = isset($params["action"]) ? $params["action"] : "default";
$module = isset($params["module"]) ? $params["module"] . ":" : "";
unset($params["action"]);
$this->destination = "{$module}{$presenter}:{$action}";
$this->params = $params;
$this->url = null;
}
}
示例6: macro
/**
* Process {macro content | modifiers}
* @param string
* @param string
* @param string
* @return string
*/
public function macro($macro, $content = '', $modifiers = '')
{
if (func_num_args() === 1) { // {macro val|modifiers}
list(, $macro, $content, $modifiers) = String::match($macro, '#^(/?[a-z0-9.:]+)?(.*?)(\\|[a-z](?:'.LatteFilter::RE_STRING.'|[^\'"]+)*)?$()#is');
$content = trim($content);
}
if ($macro === '') {
$macro = substr($content, 0, 2);
if (!isset($this->macros[$macro])) {
$macro = substr($content, 0, 1);
if (!isset($this->macros[$macro])) {
return FALSE;
}
}
$content = substr($content, strlen($macro));
} elseif (!isset($this->macros[$macro])) {
return FALSE;
}
$closing = $macro[0] === '/';
if ($closing) {
$node = array_pop($this->nodes);
if (!$node || "/$node->name" !== $macro || ($content && !String::startsWith("$node->content ", "$content ")) || $modifiers) {
$macro .= $content ? ' ' : '';
throw new LatteException("Unexpected macro {{$macro}{$content}{$modifiers}}"
. ($node ? ", expecting {/$node->name}" . ($content && $node->content ? " or eventually {/$node->name $node->content}" : '') : ''), 0, $this->filter->line);
}
$node->content = $node->modifiers = ''; // back compatibility
} else {
$node = (object) NULL;
$node->name = $macro;
$node->content = $content;
$node->modifiers = $modifiers;
if (isset($this->macros["/$macro"])) {
$this->nodes[] = $node;
}
}
$This = $this;
return String::replace(
$this->macros[$macro],
'#%(.*?)%#',
function ($m) use ($This, $node) {
if ($m[1]) {
return callback($m[1][0] === ':' ? array($This, substr($m[1], 1)) : $m[1])
->invoke($node->content, $node->modifiers);
} else {
return $This->formatMacroArgs($node->content);
}
}
);
}
示例7: contextTag
/**
* Handles CONTEXT_TAG.
*/
private function contextTag()
{
$matches = $this->match('~
(?P<end>\ ?/?>)(?P<tagnewline>[\ \t]*(?=\r|\n))?| ## end of HTML tag
'.$this->macroRe.'| ## curly tag
\s*(?P<attr>[^\s/>={]+)(?:\s*=\s*(?P<value>["\']|[^\s/>{]+))? ## begin of HTML attribute
~xsi');
if (!$matches || !empty($matches['macro']) || !empty($matches['comment'])) { // EOF or {macro}
} elseif (!empty($matches['end'])) { // end of HTML tag />
$tag = end($this->tags);
$isEmpty = !$tag->closing && (strpos($matches['end'], '/') !== FALSE || isset(Nette\Web\Html::$emptyElements[strtolower($tag->name)]));
if ($isEmpty) {
$matches[0] = (Nette\Web\Html::$xhtml ? ' />' : '>') . (isset($matches['tagnewline']) ? $matches['tagnewline'] : '');
}
if ($tag->isMacro || !empty($tag->attrs)) {
if ($tag->isMacro) {
$code = $this->handler->tagMacro(substr($tag->name, strlen(self::HTML_PREFIX)), $tag->attrs, $tag->closing);
if ($code === FALSE) {
throw new LatteException("Unknown tag-macro <$tag->name>", 0, $this->line);
}
if ($isEmpty) {
$code .= $this->handler->tagMacro(substr($tag->name, strlen(self::HTML_PREFIX)), $tag->attrs, TRUE);
}
} else {
$code = substr($this->output, $tag->pos) . $matches[0] . (isset($matches['tagnewline']) ? "\n" : '');
$code = $this->handler->attrsMacro($code, $tag->attrs, $tag->closing);
if ($code === FALSE) {
throw new LatteException("Unknown macro-attribute " . self::HTML_PREFIX . implode(' or ' . self::HTML_PREFIX, array_keys($tag->attrs)), 0, $this->line);
}
if ($isEmpty) {
$code = $this->handler->attrsMacro($code, $tag->attrs, TRUE);
}
}
$this->output = substr_replace($this->output, $code, $tag->pos);
$matches[0] = ''; // remove from output
}
if ($isEmpty) {
$tag->closing = TRUE;
}
if (!$tag->closing && (strcasecmp($tag->name, 'script') === 0 || strcasecmp($tag->name, 'style') === 0)) {
$this->context = self::CONTEXT_CDATA;
$this->escape = strcasecmp($tag->name, 'style') ? 'Nette\Templates\TemplateHelpers::escapeJs' : 'Nette\Templates\TemplateHelpers::escapeCss';
} else {
$this->context = self::CONTEXT_TEXT;
$this->escape = 'Nette\Templates\TemplateHelpers::escapeHtml';
if ($tag->closing) array_pop($this->tags);
}
} else { // HTML attribute
$name = $matches['attr'];
$value = isset($matches['value']) ? $matches['value'] : '';
// special attribute?
if ($isSpecial = String::startsWith($name, self::HTML_PREFIX)) {
$name = substr($name, strlen(self::HTML_PREFIX));
}
$tag = end($this->tags);
if ($isSpecial || $tag->isMacro) {
if ($value === '"' || $value === "'") {
if ($matches = $this->match('~(.*?)' . $value . '~xsi')) { // overwrites $matches
$value = $matches[1];
}
}
$tag->attrs[$name] = $value;
$matches[0] = ''; // remove from output
} elseif ($value === '"' || $value === "'") { // attribute = "'
$this->context = self::CONTEXT_ATTRIBUTE;
$this->quote = $value;
$this->escape = strncasecmp($name, 'on', 2)
? (strcasecmp($name, 'style') ? 'Nette\Templates\TemplateHelpers::escapeHtml' : 'Nette\Templates\TemplateHelpers::escapeHtmlCss')
: 'Nette\Templates\TemplateHelpers::escapeHtmlJs';
}
}
return $matches;
}
示例8: json_encode
// check directory
if ($root === false || $dir === false || !String::startsWith($dir, $root) || !is_dir($dir)) {
echo json_encode(array("error" => "Problem with directory."));
exit;
}
$directories = array();
$files = array();
// up
if ($root !== $dir) {
$dirPieces = explode("/", $folder);
array_pop($dirPieces);
$directories[] = array("type" => "up", "name" => "..", "key" => implode("/", $dirPieces));
}
foreach (new DirectoryIterator($dir) as $fileInfo) {
$filename = $fileInfo->getFileName();
// skip hidden files, . and ..
if (String::startsWith($filename, ".")) {
continue;
}
if ($fileInfo->isDir()) {
$directories[] = array("type" => "folder", "name" => $filename, "key" => ($folder ? "{$folder}/" : "") . $filename);
} else {
$isImage = @getImageSize($fileInfo->getPathName()) ? true : false;
if ($isImage) {
$files[] = array("type" => "image", "name" => $filename, "insertUrl" => FILES_IMAGE_INCLUDE_PREFIX . ($folder ? "{$folder}/" : "") . $filename, "description" => "", "thumbnailKey" => ($folder ? "{$folder}/" : "") . $filename);
} else {
$files[] = array("type" => "file", "name" => $filename, "insertUrl" => FILES_FILE_INCLUDE_PREFIX . ($folder ? "{$folder}/" : "") . $filename, "description" => "");
}
}
}
echo json_encode(array("list" => array_merge($directories, $files)));
示例9: dirname
require_once dirname(__FILE__) . '/paths.php';
$httpRequest = new HttpRequest();
$file = $httpRequest->getFile("file");
$folder = $httpRequest->getPost("folder", "");
$state = array();
$root = realpath(FILES_BASE_PATH);
$dir = realpath(FILES_BASE_PATH . "/" . $folder);
// security check
//if (!$allowed) {
// $state["error"] = "You are not allowed to upload files.";
//}
if (empty($file)) {
$state["error"] = "No file was uploaded";
}
// check directory
if ($root === false || $dir === false || !String::startsWith($dir, $root) || !is_dir($dir) || !is_writable($dir)) {
$state["error"] = "Problem with directory to upload.";
}
if (!empty($state["error"])) {
die(json_encode($state));
}
if ($file->isOk()) {
$filename = String::webalize($file->getName(), ".");
$success = @$file->move("{$dir}/{$filename}");
if ($success) {
// nastavit typ - je to obrázek?
$type = @$file->getImageSize() ? "image" : "file";
$prefix = $type == "image" ? FILES_IMAGE_INCLUDE_PREFIX : FILES_FILE_INCLUDE_PREFIX;
$state["filename"] = $prefix . ($folder ? "{$folder}/" : "") . $filename;
$state["type"] = $type;
} else {
示例10: parseTypeHints
private function parseTypeHints() {
$line = $this->currentToken[2];
// remove function name and reference, we don't need it
$token = $this->getNextToken();
while($this->isAllowed($token, array("&", T_STRING, T_WHITESPACE))) {
$token = $this->getNextToken();
}
while (!$this->isAllowed($token, ")")) {
$name = String::lower($this->parseName());
if(strlen($name) && !String::startsWith($name, '$') && FALSE === array_search($name, $this->reserved)) {
$this->fileInfo[$this->currentFile][$this->namespace][self::NS_USED_CLASS][$name] = $line;
}
while(!$this->isAllowed($token, array(",",")"))) {
$token = $this->getNextToken();
}
if(!$this->isAllowed($token, ")")) {
$token = $this->getNextToken();
if($this->isAllowed($token, array(T_NS_SEPARATOR, T_STRING))) {
$this->returnToken($token);
}
}
}
}
示例11: actionListFiles
/**
* File browser - projít soubory
* @param string $folder
*/
public function actionListFiles($folder = "")
{
// check rights
if (!$this->getUser()->isInRole("admin")) {
$this->sendError("Access denied.");
}
try {
$folderPath = $this->getFolderPath($folder);
} catch (InvalidArgumentException $e) {
$this->sendError("Folder does not exist or is not writeable.");
}
// list of files
$folders = array();
$files = array();
// up
if ($folder !== "") {
$lastPos = strrpos($folder, "/");
$key = $lastPos === false ? "" : substr($folder, 0, $lastPos);
$folders[] = array("type" => "up", "name" => "..", "key" => $key);
}
foreach (new DirectoryIterator($folderPath) as $fileInfo) {
$fileName = $fileInfo->getFileName();
// skip hidden files, . and ..
if (String::startsWith($fileName, ".")) {
continue;
}
// filename with folder
$key = ($folder ? $folder . "/" : "") . $fileName;
// directory
if ($fileInfo->isDir()) {
$folders[] = array("type" => "folder", "name" => $fileName, "key" => $key);
// file
} elseif ($fileInfo->isFile()) {
// image
if (@getImageSize($fileInfo->getPathName())) {
$thumbFileName = $this->thumbnailFileName($fileInfo->getPathName());
if (file_exists($this->tempDir . "/" . $thumbFileName)) {
$thumbnailKey = $this->tempUri . "/" . $thumbFileName;
} else {
$thumbnailKey = $this->link("thumbnail", $key);
}
$files[] = array("type" => "image", "name" => $fileName, "insertUrl" => $key, "description" => $fileName, "thumbnailKey" => $thumbnailKey);
// other file
} else {
$files[] = array("type" => "file", "name" => $fileName, "insertUrl" => $this->baseFolderUri . ($folder ? "{$folder}/" : "") . $fileName, "description" => $fileName);
}
}
}
// send response
$this->sendResponse(new JsonResponse(array("list" => array_merge($folders, $files))));
}
示例12: fetchNameAndModifiers
private static function fetchNameAndModifiers($code)
{
$name = self::$latte->fetchToken($code);
$modifiers = self::$latte->formatArray($code);
$name = String::startsWith($name, '$') ? $name : "'{$name}'";
$modifiers = $modifiers ?: "array()";
return array($name, $modifiers);
}