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


PHP str::startsWith方法代码示例

本文整理汇总了PHP中str::startsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP str::startsWith方法的具体用法?PHP str::startsWith怎么用?PHP str::startsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在str的用法示例。


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

示例1: env

/**
 * Gets the value of an environment variable. Supports boolean, empty and null.
 *
 * @param  string  $key
 * @param  mixed   $default
 * @return mixed
 */
function env($key, $default = null)
{
    $value = getenv($key);
    if ($value === false) {
        return $default;
    }
    switch (strtolower($value)) {
        case 'true':
        case '(true)':
            return true;
        case 'false':
        case '(false)':
            return false;
        case 'empty':
        case '(empty)':
            return '';
        case 'null':
        case '(null)':
            return;
    }
    if (\str::startsWith($value, '"') && \str::endsWith($value, '"')) {
        return substr($value, 1, -1);
    }
    return $value;
}
开发者ID:evendev,项目名称:apex-kirby,代码行数:32,代码来源:helpers.php

示例2: data

 public function data($key = null, $value = null)
 {
     if (is_null($key)) {
         $data = array();
         foreach ($this->attr as $key => $val) {
             if (str::startsWith($key, 'data-')) {
                 $data[$key] = $val;
             }
         }
         return $data;
     } else {
         if (is_array($key)) {
             foreach ($key as $k => $v) {
                 $this->data($k, $v);
             }
             return $this;
         } else {
             if (is_null($value)) {
                 return a::get($this->attr, 'data-' . $key);
             } else {
                 $this->attr['data-' . $key] = $value;
                 return $this;
             }
         }
     }
 }
开发者ID:chrishiam,项目名称:LVSL,代码行数:26,代码来源:brick.php

示例3: license

 public function license()
 {
     $key = c::get('license');
     $type = 'trial';
     /**
      * Hey stranger, 
      * 
      * So this is the mysterious place where the panel checks for 
      * valid licenses. As you can see, this is not reporting
      * back to any server and the license keys are rather simple to 
      * hack. If you really feel like removing the warning in the panel
      * or tricking Kirby into believing you bought a valid license even 
      * if you didn't, go for it! But remember that literally thousands of 
      * hours of work have gone into Kirby in order to make your 
      * life as a developer, designer, publisher, etc. easier. If this 
      * doesn't mean anything to you, you are probably a lost case anyway. 
      * 
      * Have a great day! 
      * 
      * Bastian
      */
     if (str::startsWith($key, 'K2-PRO') and str::length($key) == 39) {
         $type = 'Kirby 2 Professional';
     } else {
         if (str::startsWith($key, 'K2-PERSONAL') and str::length($key) == 44) {
             $type = 'Kirby 2 Personal';
         } else {
             if (str::startsWith($key, 'MD-') and str::length($key) == 35) {
                 $type = 'Kirby 1';
             } else {
                 if (str::startsWith($key, 'BETA') and str::length($key) == 9) {
                     $type = 'Kirby 1';
                 } else {
                     if (str::length($key) == 32) {
                         $type = 'Kirby 1';
                     } else {
                         $key = null;
                     }
                 }
             }
         }
     }
     $localhosts = array('::1', '127.0.01', '0.0.0.0');
     return new Obj(array('key' => $key, 'local' => in_array(server::get('SERVER_ADDR'), $localhosts) or server::get('SERVER_NAME') == 'localhost', 'type' => $type));
 }
开发者ID:v1m0,项目名称:kirby-f6,代码行数:45,代码来源:panel.php

示例4: __construct

 public function __construct($field)
 {
     $this->field = $field;
     if (is_array($field->options)) {
         $this->options = $field->options;
     } else {
         if (v::url($field->options)) {
             $response = remote::get($field->options);
             $options = @json_decode($response->content(), true);
             if (is_array($options)) {
                 $this->options = $options;
             } else {
                 $this->options = array();
             }
         } else {
             if (!$field->page) {
                 $this->options = array();
             } else {
                 if ($field->options == 'query') {
                     $defaults = array('page' => $field->page->id(), 'fetch' => 'children', 'value' => '{{uid}}', 'text' => '{{title}}', 'flip' => false, 'template' => false);
                     $query = array_merge($defaults, $field->query);
                     // dynamic page option
                     // ../
                     // ../../ etc.
                     if (str::startsWith($query['page'], '../')) {
                         $currentPage = $field->page;
                         $path = $query['page'];
                         while (str::startsWith($path, '../')) {
                             if ($parent = $currentPage->parent()) {
                                 $currentPage = $parent;
                             } else {
                                 break;
                             }
                             $path = str::substr($path, 3);
                         }
                         $page = $currentPage;
                     } else {
                         $page = page($query['page']);
                     }
                     $items = $this->items($page, $query['fetch']);
                     if ($query['template']) {
                         $items = $items->filter(function ($item) use($query) {
                             return in_array(str::lower($item->intendedTemplate()), array_map('str::lower', (array) $query['template']));
                         });
                     }
                     if ($query['flip']) {
                         $items = $items->flip();
                     }
                     foreach ($items as $item) {
                         $value = $this->tpl($query['value'], $item);
                         $text = $this->tpl($query['text'], $item);
                         $this->options[$value] = $text;
                     }
                 } else {
                     if ($items = $this->items($field->page, $field->options)) {
                         foreach ($items as $item) {
                             if (is_a($item, 'Page')) {
                                 $this->options[$item->uid()] = (string) $item->title();
                             } else {
                                 if (is_a($item, 'File')) {
                                     $this->options[$item->filename()] = (string) $item->filename();
                                 }
                             }
                         }
                     } else {
                         $this->options = array();
                     }
                 }
             }
         }
     }
     // sorting
     if (!empty($this->field->sort)) {
         switch (strtolower($this->field->sort)) {
             case 'asc':
                 asort($this->options);
                 break;
             case 'desc':
                 arsort($this->options);
                 break;
         }
     }
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:83,代码来源:fieldoptions.php

示例5: checkUpload

 protected function checkUpload($file, $blueprint)
 {
     if (strtolower($file->extension()) == kirby()->option('content.file.extension', 'txt')) {
         throw new Exception('Content files cannot be uploaded');
     } else {
         if (strtolower($file->extension()) == 'php' or str::contains($file->extension(), 'php') or in_array($file->mime(), f::$mimes['php'])) {
             throw new Exception('PHP files cannot be uploaded');
         } else {
             if (strtolower($file->extension()) == 'html' or $file->mime() == 'text/html') {
                 throw new Exception('HTML files cannot be uploaded');
             } else {
                 if (strtolower($file->extension()) == 'exe' or $file->mime() == 'application/x-msdownload') {
                     throw new Exception('EXE files cannot be uploaded');
                 } else {
                     if (strtolower($file->filename()) == '.htaccess') {
                         throw new Exception('htaccess files cannot be uploaded');
                     } else {
                         if (str::startsWith($file->filename(), '.')) {
                             throw new Exception('Invisible files cannot be uploaded');
                             // Files blueprint option 'type'
                         } else {
                             if (count($blueprint->files()->type()) > 0 and !in_array($file->type(), $blueprint->files()->type())) {
                                 throw new Exception('Page only allows: ' . implode(', ', $blueprint->files()->type()));
                                 // Files blueprint option 'size'
                             } else {
                                 if ($blueprint->files()->size() and f::size($file->root()) > $blueprint->files()->size()) {
                                     throw new Exception('Page only allows file size of ' . f::niceSize($blueprint->files()->size()));
                                     // Files blueprint option 'width'
                                 } else {
                                     if ($file->type() == 'image' and $blueprint->files()->width() and $file->width() > $blueprint->files()->width()) {
                                         throw new Exception('Page only allows image width of ' . $blueprint->files()->width() . 'px');
                                         // Files blueprint option 'height'
                                     } else {
                                         if ($file->type() == 'image' and $blueprint->files()->height() and $file->height() > $blueprint->files()->height()) {
                                             throw new Exception('Page only allows image height of ' . $blueprint->files()->height() . 'px');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:46,代码来源:files.php

示例6: filterFields

 /**
  * @param array $event the 'raw' event array of fields.
  * @return the array of fields without the 'private' fields with keys
  */
 private static function filterFields($event)
 {
     foreach (array_keys($event) as $key) {
         if (str::startsWith($key, '_')) {
             unset($event[$key]);
         }
     }
     return $event;
 }
开发者ID:igorqr,项目名称:kirby-extensions,代码行数:13,代码来源:Event.php

示例7: sections

 *
 * @param Page $parent 
 * @return Collection A collection of Section objects
 * @author fenixkim
 */
function sections(Page $parent = null)
{
    // Fetchs the current page if $parent is null
    return new Sections($parent ?: page());
}
$kirby->set('page::method', 'sections', function ($page) {
    return new Sections($page ?: page());
});
$kirby->set('page::method', 'isSection', function ($page) {
    return Sections::pageIsSection($page);
});
$kirby->set('page::method', 'countSections', function ($page) {
    return $page->sections()->count();
});
$kirby->set('page::method', 'hasSections', function ($page) {
    return $page->sections()->count() > 0;
});
$kirby->set('page::method', 'avoidDirectLink', function ($page, $redirectToParent = true, $addHash = true) {
    Sections::avoidDirectLink($page, $redirectToParent, $addHash);
    return $page;
});
$kirby->set('pages::method', 'notSections', function ($pages) {
    return $pages->filter(function ($child) {
        return !str::startsWith($child->template(), Sections::prefix());
    });
});
开发者ID:aoimedia,项目名称:KirbySections,代码行数:31,代码来源:sections.php

示例8: foreach

<table>
	<thead>
		<tr>
			<th>Field</th>
			<th>Value</th>
		</tr>
	</thead>
	<tbody>
<?php 
foreach ($form as $field => $value) {
    if (str::startsWith($field, '_')) {
        continue;
    }
    if (is_array($value)) {
        $value = implode(', ', array_filter($value, function ($i) {
            return $i !== '';
        }));
    }
    ?>
		<tr>
			<td><?php 
    echo ucfirst($field);
    ?>
</td>
			<td><?php 
    echo $value;
    ?>
</td>
		</tr>
<?php 
}
开发者ID:fetzi,项目名称:kirby-uniform,代码行数:31,代码来源:uniform-email-table.php

示例9: clean

 public function clean($root)
 {
     if (!is_dir($root)) {
         throw new Exception('The given directory does not exist');
     }
     if (!str::startsWith($root, $this->root)) {
         throw new Exception('Invalid directory. Must be within the library');
     }
     while ($root != $this->root) {
         $files = dir::read($root);
         if (count($files) === 0) {
             dir::remove($root);
         } else {
             break;
         }
         $root = dirname($root);
     }
 }
开发者ID:Zegnat,项目名称:library,代码行数:18,代码来源:library.php

示例10: reset

 public function reset()
 {
     if ($this->field) {
         return $this->store()->reset();
     } else {
         foreach (s::get() as $key => $value) {
             if (str::startsWith($key, $this->id)) {
                 s::remove($key);
             }
         }
     }
 }
开发者ID:irenehilber,项目名称:kirby-base,代码行数:12,代码来源:structure.php

示例11: checkUpload

 public function checkUpload($file)
 {
     $filesettings = $this->blueprint->files();
     $forbiddenExtensions = array('php', 'html', 'htm', 'exe', kirby()->option('content.file.extension', 'txt'));
     $forbiddenMimes = array_merge(f::$mimes['php'], array('text/html', 'application/x-msdownload'));
     $extension = strtolower($file->extension());
     // files without extension are not allowed
     if (empty($extension)) {
         throw new Exception(l('files.add.error.extension.missing'));
     }
     // block forbidden extensions
     if (in_array($extension, $forbiddenExtensions)) {
         throw new Exception(l('files.add.error.extension.forbidden'));
     }
     // especially block any connection that contains php
     if (str::contains($extension, 'php')) {
         throw new Exception(l('files.add.error.extension.forbidden'));
     }
     // block forbidden mimes
     if (in_array(strtolower($file->mime()), $forbiddenMimes)) {
         throw new Exception(l('files.add.error.mime.forbidden'));
     }
     // Block htaccess files
     if (strtolower($file->filename()) == '.htaccess') {
         throw new Exception(l('files.add.error.htaccess'));
     }
     // Block invisible files
     if (str::startsWith($file->filename(), '.')) {
         throw new Exception(l('files.add.error.invisible'));
     }
     // Files blueprint option 'type'
     if (count($filesettings->type()) > 0 and !in_array($file->type(), $filesettings->type())) {
         throw new Exception(l('files.add.blueprint.type.error') . implode(', ', $filesettings->type()));
     }
     // Files blueprint option 'size'
     if ($filesettings->size() and f::size($file->root()) > $filesettings->size()) {
         throw new Exception(l('files.add.blueprint.size.error') . f::niceSize($filesettings->size()));
     }
     // Files blueprint option 'width'
     if ($file->type() == 'image' and $filesettings->width() and $file->width() > $filesettings->width()) {
         throw new Exception('Page only allows image width of ' . $filesettings->width() . 'px');
     }
     // Files blueprint option 'height'
     if ($file->type() == 'image' and $filesettings->height() and $file->height() > $filesettings->height()) {
         throw new Exception('Page only allows image height of ' . $filesettings->height() . 'px');
     }
 }
开发者ID:robinandersen,项目名称:robin,代码行数:47,代码来源:uploader.php

示例12: isPatterns

 function isPatterns()
 {
     return str::startsWith(url::current(), $this->url_patterns);
 }
开发者ID:jenstornell,项目名称:kirby-redirect-to-slash,代码行数:4,代码来源:redirect-to-slash.php

示例13: load

 /**
  * Load plugin options.
  *
  * @return array
  */
 public function load()
 {
     // Retrieve all plugin options from the configuration starting with a
     // prefix matching the plugin name
     $prefix = $this->namespace . '.';
     $keys = array_keys(c::$data);
     $keys = array_filter($keys, function ($key) use($prefix) {
         return str::startsWith($key, $prefix);
     });
     // Remove prefix and collect data
     $options = array();
     foreach ($keys as $key) {
         $option = str::substr($key, str::length($prefix));
         $options[$option] = c::$data[$key];
     }
     // Merge plugin settings with defaults
     $defaults = $this->defaults();
     if (is_array($defaults) && !empty($defaults)) {
         $options = array_merge($defaults, $options);
     }
     return $options;
 }
开发者ID:buditanrim,项目名称:kirby-comments,代码行数:27,代码来源:config.php

示例14: pageIsSection

 /**
  * Check if a Page is a Section
  *
  * @param Page $page 
  * @return bool
  * @author fenixkim
  */
 public static function pageIsSection(Page $page)
 {
     return str::startsWith($page->template(), static::prefix());
 }
开发者ID:aoimedia,项目名称:KirbySections,代码行数:11,代码来源:sections.php

示例15: kirby

<?php

if (c::get('cdn.content')) {
    kirby()->urls()->content = c::get('cdn.content');
}
if (c::get('cdn.thumbs')) {
    thumb::$defaults['url'] = c::get('cdn.thumbs');
}
if (c::get('cdn.assets')) {
    $original = url::$to;
    url::$to = function () use($original) {
        $url = call($original, func_get_args());
        if (!str::startsWith($url, kirby()->urls()->index())) {
            return $url;
        }
        if (str::contains($url, '/panel/assets')) {
            return $url;
        }
        $url = preg_replace_callback('!.*?\\/assets\\/(.*)$!', function ($match) {
            return c::get('cdn.assets') . '/' . $match[1];
        }, $url);
        return $url;
    };
}
开发者ID:cfreitag,项目名称:plugins,代码行数:24,代码来源:cdn.php


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