本文整理汇总了PHP中startsWith函数的典型用法代码示例。如果您正苦于以下问题:PHP startsWith函数的具体用法?PHP startsWith怎么用?PHP startsWith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startsWith函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_edge
function add_edge($_previous_as, $_as, $attrs = array())
{
global $edges, $graph;
$edge_array = array($_previous_as => $_as);
if (!array_key_exists(gek($_previous_as, $_as), $edges)) {
$attrs['splines'] = "true";
$edge = array($edge_array, $attrs);
$graph->addEdge($edge_array, $attrs);
$edges[gek($_previous_as, $_as)] = $edge;
} else {
if (array_key_exists('label', $attrs)) {
$e =& $edges[gek($_previous_as, $_as)];
$label_without_star = str_replace("*", "", $attrs['label']);
$labels = explode("\r", $e[1]['label']);
if (!in_array($label_without_star . "*", $labels)) {
$tmp_labels = array();
foreach ($labels as $l) {
if (!startsWith($l, $label_without_star)) {
$labels[] = $l;
}
}
$labels = array_merge(array($attrs['label']), $tmp_labels);
$cmp = function ($a, $b) {
return endsWith($a, "*") ? -1 : 1;
};
usort($labels, $cmp);
$label = escape(implode("\r", $labels));
$e[1]['label'] = $label;
}
}
}
return $edges[gek($_previous_as, $_as)];
}
示例2: 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 value($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 (startsWith($value, '"') && endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
示例3: parseCommand
function parseCommand($file, $message)
{
$output = '';
if (startsWith($message, '/')) {
$message = substr($message, 1);
$splits = explode(' ', $message);
$output = $splits[2];
switch ($splits[0]) {
case 'facebook':
switch ($splits[1]) {
case '-user':
$analyzer = new FacebookProfiler($splits[2]);
$analyzer->analyze();
$output = $analyzer->getResponse();
break;
case '-search':
$searcher = new FacebookSearcher($splits[2]);
$output = $searcher->getResponse();
break;
}
break;
case 'whitespace':
$name = $splits[1];
$city = $splits[2];
$state = $splits[3];
//$whitepages = new WhitePages('537775405e1660bfb260b59ace642e37');
break;
}
if (strlen($output) > 0) {
fwrite(fopen($file, 'a'), "<span>Salty Stalker</span>" . '<span class="test">' . ($output = str_replace("\n", " ", $output) . '</span>' . "\n"));
}
return true;
}
return false;
}
示例4: search
function search($title)
{
$str = strtolower($title);
$str = str_replace(array(" "), "_", $str);
$str = str_replace(array("(", ")", "-", ":", ".", ";", ",", "'", '"', "+", "#"), "", $str);
if (strlen($str) <= 2) {
return FALSE;
}
do {
$str2 = urlencode($str);
$data = @file_get_contents("http://sg.media-imdb.com/suggests/" . substr($str2, 0, 1) . "/{$str2}.json");
$str = substr($str, 0, -1);
} while ($data === FALSE && strlen($str) > 2);
if ($data === FALSE) {
# http_response_code(404);
# echo "Nope";
return FALSE;
}
$json = substr($data, 5 + strlen($str) + 2, -1);
$obj = json_decode($json, TRUE);
#print_r($obj);
$res = array('show' => array());
if (isset($obj['d'])) {
foreach ($obj['d'] as $show) {
#echo strtolower($show['l'])."\n";
if (isset($show['q']) && $show['q'] == "TV series" && startsWith(strtolower($show['l']), strtolower($title))) {
$res['show'][] = array('imdb_id' => $show['id'], 'name' => $show['l'], 'year' => $show['y'], 'img' => isset($show['i']) ? $show['i'][0] : '');
}
}
}
return $res;
}
示例5: run_sql_file
function run_sql_file($location)
{
//load file
$commands = file_get_contents($location);
//delete comments
$lines = explode("\n", $commands);
$commands = '';
foreach ($lines as $line) {
$line = trim($line);
if ($line && !startsWith($line, '--')) {
$commands .= $line . "\n";
}
}
//convert to array
$commands = explode(";", $commands);
//run commands
$total = $success = 0;
foreach ($commands as $command) {
if (trim($command)) {
$success += @mysql_query($command) == false ? 0 : 1;
$total += 1;
}
}
//return number of successful queries and total number of queries found
return array("success" => $success, "total" => $total);
}
示例6: loadUpdatesFromDir
function loadUpdatesFromDir($output, $outputIndexes, $dir, $fileFilter, $timestamp)
{
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (startsWith(strtolower($file), strtolower($fileFilter))) {
$indexName = $file;
$filename = $dir . $file;
//"./test112.zip";
$size = number_format(filesize($filename) / (1024.0 * 1024.0), 1, '.', '');
$containerSize = filesize($filename);
$contentSize = filesize($filename);
$date = date('d.m.Y', filemtime($filename));
$timestampF = filemtime($filename);
if ($timestampF > intval(substr($timestamp, 0, -3))) {
$out = $output->createElement('update');
$outputIndexes->appendChild($out);
$out->setAttribute("updateDate", substr($file, -strlen('.obf.gz') - 8, -strlen('.obf.gz')));
$out->setAttribute("containerSize", $containerSize);
$out->setAttribute("contentSize", $contentSize);
$out->setAttribute("timestamp", $timestampF * 1000);
$out->setAttribute("date", $date);
$out->setAttribute("size", $size);
$out->setAttribute("name", $indexName);
}
}
}
closedir($dh);
}
} else {
print $dir . " not a directory!\n";
}
}
示例7: generateUrl
function generateUrl() {
//$newHost = "https://nowsci.com/s/";
$host = OCP\Config::getAppValue('shorten', 'host', '');
$type = OCP\Config::getAppValue('shorten', 'type', '');
$api = OCP\Config::getAppValue('shorten', 'api', '');
$curUrl = $_POST['curUrl'];
$ret = "";
if (isset($type) && ($type == "" || $type == "internal")) {
if ($host == "" || startsWith($curUrl, $host)) {
$ret = $curUrl;
} else {
$shortcode = getShortcode($curUrl);
$newUrl = $host."?".$shortcode;
$ret = $newUrl;
}
} elseif ($type == "googl") {
if ($api && $api != "") {
require_once __DIR__ . '/../lib/class.googl.php';
$googl = new googl($api);
$short = $googl->s($curUrl);
$ret = $short;
} else {
$ret = $curUrl;
}
} else {
$ret = $curUrl;
}
return $ret;
}
示例8: join_url
/**
* URL Utility
*/
function join_url($url1, $url2)
{
if (strlen($url1) <= 0 || strlen($url2) <= 0) {
return '';
} elseif (strlen($url1) <= 0) {
return trim($url2);
} elseif (strlen($url2) <= 0) {
return trim($url1);
}
$url1 = preg_match('{^https?:/{0,2}$}i', $url1) ? '' : trim($url1);
$url2 = trim($url2);
if (preg_match('{^https?://}i', $url2)) {
return $url2;
} elseif (startsWith($url2, '/')) {
if ((startsWith($url1, 'http://') || startsWith($url1, 'https://')) && preg_match('{^(https?://[^/]+)/?}i', $url1, $match)) {
return "{$match[1]}{$url2}";
} else {
return $url2;
}
} elseif (preg_match('{^[?#]}i', $url2)) {
return "{$url1}{$url2}";
} elseif (preg_match('{^(https?://[^/]+)$}i', $url1, $match)) {
return "{$match[1]}/{$url2}";
} elseif (preg_match('{^(.+/)[^/]*$}i', $url1, $match)) {
return "{$match[1]}{$url2}";
} else {
return $url2;
}
}
示例9: __construct
public function __construct()
{
$lines = file(PATH . ".htaccess");
$activated = false;
foreach ($lines as $line) {
if (startsWith($line, '#URLS_PY START#')) {
$activated = true;
} elseif (startsWith($line, '#URLS_PY END#')) {
$activated = false;
}
if ($activated && $line != '' && startsWith($line, 'RewriteRule ^')) {
$string_before_url = '\\^';
$string_after_url = '\\$';
$regex_url = "/" . $string_before_url . "(.*?)" . $string_after_url . "/";
preg_match_all($regex_url, $line, $matches_url);
$match_url = $matches_url[1][0];
$match_url = '/' . str_replace('([^/\\.]+)/?', '%s/', $match_url);
$string_before_namespace = '###';
$string_after_namespace = '###';
$regex_namespace = "/" . $string_before_namespace . "(.*?)" . $string_after_namespace . "/";
preg_match_all($regex_namespace, $line, $matches_namespace);
$match_namespace = $matches_namespace[1][0];
if (isset(UrlsPy::$patterns[$match_namespace])) {
if (is_array(UrlsPy::$patterns[$match_namespace])) {
UrlsPy::$patterns[$match_namespace][] = $match_url;
} else {
UrlsPy::$patterns[$match_namespace] = array(UrlsPy::$patterns[$match_namespace], $match_url);
}
} else {
UrlsPy::$patterns[$match_namespace] = $match_url;
}
}
}
}
示例10: _identify
function _identify($str)
{
$msg_identifier = "]8úü";
$server_delivery_identifier = "Œ";
$client_delivery_identifier = "½";
$acc_info_iden = "™½§”";
$last_seen_ident = "H8úü";
$last_seen_ident2 = "{½L‹";
if (startsWith($str, $msg_identifier, 3)) {
if (endsWith($str, $server_delivery_identifier)) {
return 'server_delivery_report';
} else {
if (endsWith($str, $client_delivery_identifier)) {
return 'client_delivery_report';
} else {
return 'msg';
}
}
} else {
if (startsWith($str, $acc_info_iden, 3)) {
return 'account_info';
} else {
if (startsWith($str, $last_seen_ident, 3) && strpos($str, $last_seen_ident2)) {
return 'last_seen';
}
}
}
}
示例11: __construct
/**
* @constructor
*
* @param {array} $rules Redirect rules
* @param {callable|string} $rules[][source] Regex, plain string startsWith() or callback matcher func,
* @param {string} $rules[][target] String for redirection, can use backreference on regex,
* @param {?int} $rules[][options] Redirection $options, or internal by default,
* @param {?string} $options[source] Base path to match against requests, defaults to root.
* @param {string|callable} $options[target] Redirects to a static target, or function($request) returns a string;
*/
public function __construct($rules)
{
// rewrite all URLs
if (is_string($rules)) {
$rules = array('*' => $rules);
}
$rules = util::wrapAssoc($rules);
$this->rules = array_reduce($rules, function ($result, $rule) {
$rule = array_select($rule, array('source', 'target', 'options'));
// note: make sure source is callback
if (is_string($rule['source'])) {
// regex
if (@preg_match($rule['source'], null) !== false) {
$rule['source'] = matches($rule['source']);
if (is_string($rule['target'])) {
$rule['target'] = compose(invokes('uri', array('path')), replaces($rule['source'], $rule['target']));
}
} else {
if (!is_callable($rule['source'])) {
$rule['source'] = startsWith($rule['source']);
if (is_string($rule['target'])) {
$rule['target'] = compose(invokes('uri', array('path')), replaces('/^' . preg_quote($rule['source']) . '/', $rule['target']));
}
}
}
}
if (!is_callable($rule['source'])) {
throw new InvalidArgumentException('Source must be string, regex or callable.');
}
$result[] = $rule;
return $result;
}, array());
}
示例12: __call
public function __call($sName, $aArg)
{
if (startsWith($sName, '_')) {
return Curry::make(array($this, '__force'), array(substr($sName, 1), $aArg));
}
return call_user_func_array(array($this->__obj->{$this->__name}, $sName), $aArg);
}
示例13: routeRequests
private static function routeRequests()
{
//CHECK REQUEST LENGHT. MAX=256
if (strstr(self::$requestURI, 'index.php') || strlen($_SERVER['REQUEST_URI']) > 256) {
header('Location: /' . Core::readConfig('SITE/WWW'));
exit;
}
self::$requestURI = str_replace(Core::readConfig('SITE/WWW'), '', self::$requestURI);
self::$requestURI = explode('?', self::$requestURI);
self::$requestURI = self::$requestURI[0];
// fuq de ?
while (strstr(self::$requestURI, '//')) {
self::$requestURI = str_replace('//', '/', self::$requestURI);
}
$requestParams = explode('/', self::$requestURI);
$requestPage = strtolower(startsWith($requestParams[1], '/') ? $requestParams[1] : '/' . $requestParams[1]);
$requestParams = array_slice($requestParams, 2);
if (array_key_exists($requestPage, self::$routes)) {
if (isset($requestParams[0]) && $requestParams[0] == '') {
$requestParams = null;
}
Core::requireController(self::$routes[$requestPage], $requestParams);
} else {
Core::requireController('Redirect', array_slice(explode('/', self::$requestURI), 1));
}
}
示例14: testIsHtmlAndNoWarningFound
public function testIsHtmlAndNoWarningFound()
{
assertThat($this->pageContent, startsWith('<!DOCTYPE html>'));
$this->assertCriticalStringNotfound('PHP Notice');
$this->assertCriticalStringNotfound('PHP Fatal error');
$this->assertCriticalStringNotfound('PHP Warning');
}
示例15: getBaseUrl
public static function getBaseUrl($append_suffix = false)
{
$candidates = array();
if (isset($_GET[self::QUERY_STRING_PARAM_NAME])) {
$url = substr($_GET[self::QUERY_STRING_PARAM_NAME], 1);
$candidates[] = $url;
}
if (isset($_SERVER['HTTP_ORIGIN'])) {
$candidates[] = $_SERVER['HTTP_ORIGIN'];
}
if (isset($_SERVER['HTTP_REFERER'])) {
$candidates[] = $_SERVER['HTTP_REFERER'];
}
// Default fallback.
$base_url = self::$alt_base_urls[0];
foreach ($candidates as $candidate) {
foreach (self::$alt_base_urls as $alt_base_url) {
if ($candidate && startsWith($candidate, $alt_base_url)) {
$base_url = $alt_base_url;
}
}
}
if ($append_suffix) {
$base_url .= self::$base_url_suffix;
}
return $base_url;
}