本文整理汇总了PHP中file_get_contents函数的典型用法代码示例。如果您正苦于以下问题:PHP file_get_contents函数的具体用法?PHP file_get_contents怎么用?PHP file_get_contents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_get_contents函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: get
public function get($limit = 1024)
{
header('Content-Type: application/json');
$dates = json_decode(file_get_contents('hoa://Application/Database/Dates.json'), true);
echo json_encode(array_slice($dates, 0, $limit));
return;
}
开发者ID:Hywan,项目名称:Amine_and_Hamza,代码行数:7,代码来源:Dates.php
示例2: run
/**
* {@inheritdoc}
*/
public function run()
{
if (is_null($this->dst) || "" === $this->dst) {
return Result::error($this, 'You must specify a destination file with to() method.');
}
if (!$this->checkResources($this->files, 'file')) {
return Result::error($this, 'Source files are missing!');
}
if (file_exists($this->dst) && !is_writable($this->dst)) {
return Result::error($this, 'Destination already exists and cannot be overwritten.');
}
$dump = '';
foreach ($this->files as $path) {
foreach (glob($path) as $file) {
$dump .= file_get_contents($file) . "\n";
}
}
$this->printTaskInfo('Writing {destination}', ['destination' => $this->dst]);
$dst = $this->dst . '.part';
$write_result = file_put_contents($dst, $dump);
if (false === $write_result) {
@unlink($dst);
return Result::error($this, 'File write failed.');
}
// Cannot be cross-volume; should always succeed.
@rename($dst, $this->dst);
return Result::success($this);
}
开发者ID:greg-1-anderson,项目名称:Robo,代码行数:31,代码来源:Concat.php
示例3: up
public static function up($html, $spruce)
{
self::$tokenizer = new PHP_CodeSniffer_Tokenizers_CSS();
// TODO: parse $spruce to see if it's a path or a full Spruce string
self::$tokens = self::$tokenizer->tokenizeString(file_get_contents($spruce));
self::$tree = array();
//print_r(self::tokens);
reset(self::$tokens);
while ($t = current(self::$tokens)) {
if ($t['type'] != 'T_OPEN_TAG' && $t['type'] != 'T_DOC_COMMENT' && $t['type'] != 'T_COMMENT') {
if ($t['type'] == 'T_ASPERAND') {
$temp = next(self::$tokens);
switch ($temp['content']) {
case 'import':
next(self::$tokens);
self::addImportRule();
//print_r($temp);
continue;
case 'media':
next(self::$tokens);
self::addMediaRule();
continue;
}
} elseif ($t['type'] == 'T_STRING') {
self::addStatement();
}
}
next(self::$tokens);
}
return self::$tree;
}
开发者ID:BigBlueHat,项目名称:Spruce,代码行数:31,代码来源:Spruce.php
示例4: template
/**
* Compiles a template and writes it to a cache file, which is used for inclusion.
*
* @param string $file The full path to the template that will be compiled.
* @param array $options Options for compilation include:
* - `path`: Path where the compiled template should be written.
* - `fallback`: Boolean indicating that if the compilation failed for some
* reason (e.g. `path` is not writable), that the compiled template
* should still be returned and no exception be thrown.
* @return string The compiled template.
*/
public static function template($file, array $options = array())
{
$cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates';
$defaults = array('path' => $cachePath, 'fallback' => false);
$options += $defaults;
$stats = stat($file);
$oname = basename(dirname($file)) . '_' . basename($file, '.php');
$oname .= '_' . ($stats['ino'] ?: hash('md5', $file));
$template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php";
$template = "{$options['path']}/{$template}";
if (file_exists($template)) {
return $template;
}
$compiled = static::compile(file_get_contents($file));
if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) {
foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) {
if ($expired !== $template) {
unlink($expired);
}
}
return $template;
}
if ($options['fallback']) {
return $file;
}
throw new TemplateException("Could not write compiled template `{$template}` to cache.");
}
开发者ID:fedeisas,项目名称:lithium,代码行数:38,代码来源:Compiler.php
示例5: addFieldToModule
public function addFieldToModule($field)
{
global $log;
$fileName = 'modules/Settings/Vtiger/models/CompanyDetails.php';
$fileExists = file_exists($fileName);
if ($fileExists) {
require_once $fileName;
$fileContent = file_get_contents($fileName);
$placeToAdd = "'website' => 'text',";
$newField = "'{$field}' => 'text',";
if (self::parse_data($placeToAdd, $fileContent)) {
$fileContent = str_replace($placeToAdd, $placeToAdd . PHP_EOL . ' ' . $newField, $fileContent);
} else {
if (self::parse_data('?>', $fileContent)) {
$fileContent = str_replace('?>', '', $fileContent);
}
$fileContent = $fileContent . PHP_EOL . $placeToAdd . PHP_EOL . ' ' . $newField . PHP_EOL . ');';
}
$log->info('Settings_Vtiger_SaveCompanyField_Action::addFieldToModule - add line to modules/Settings/Vtiger/models/CompanyDetails.php ');
} else {
$log->info('Settings_Vtiger_SaveCompanyField_Action::addFieldToModule - File does not exist');
return FALSE;
}
$filePointer = fopen($fileName, 'w');
fwrite($filePointer, $fileContent);
fclose($filePointer);
return TRUE;
}
开发者ID:rcrrich,项目名称:UpdatePackages,代码行数:28,代码来源:SaveCompanyField.php
示例6: testConvertWrongConfiguration
/**
* Testing converting not valid cron configuration, expect to get exception
*
* @expectedException \InvalidArgumentException
*/
public function testConvertWrongConfiguration()
{
$xmlFile = __DIR__ . '/_files/sales_invalid.xml';
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($xmlFile));
$this->_converter->convert($dom);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:ConverterTest.php
示例7: __construct
/**
* Config
*/
public function __construct()
{
$posts = json_decode(file_get_contents(dirname(__FILE__) . '/posts.json'), true);
foreach ($posts as $key => $post) {
$this->posts[$key] = (object) $post;
}
}
开发者ID:muchlis111,项目名称:belajar-oop_php,代码行数:10,代码来源:PostJsonRepository.php
示例8: processStandardHeaders
/**
* Processes the standard headers that are not subdivided into other structs.
*/
protected function processStandardHeaders()
{
$req = $this->request;
$req->date = isset($_SERVER['REQUEST_TIME']) ? new DateTime("@{$_SERVER['REQUEST_TIME']}") : new DateTime();
if (isset($_SERVER['REQUEST_METHOD'])) {
switch ($_SERVER['REQUEST_METHOD']) {
case 'POST':
$req->protocol = 'http-post';
break;
case 'PUT':
$req->protocol = 'http-put';
break;
case 'DELETE':
$req->protocol = 'http-delete';
break;
default:
$req->protocol = 'http-get';
}
}
$req->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost.localdomain');
$req->uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
// remove the query string from the URI
$req->uri = preg_replace('@\\?.*$@', '', $req->uri);
// url decode the uri
$req->uri = urldecode($req->uri);
// remove the prefix from the URI
$req->uri = preg_replace('@^' . preg_quote($this->properties['prefix']) . '@', '', $req->uri);
$req->requestId = $req->host . $req->uri;
$req->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
$req->variables =& $_REQUEST;
if ($req->protocol == 'http-put') {
$req->body = file_get_contents("php://input");
}
}
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:37,代码来源:http.php
示例9: gameStatus
function gameStatus()
{
$homepage = file_get_contents('http://bsx.jlparry.com/status');
$xml = simplexml_load_string($homepage);
print_r($xml);
return $xml;
}
开发者ID:cambethell,项目名称:CodeIgniter-Assignment,代码行数:7,代码来源:GameState.php
示例10: testObsoleteDirectives
public function testObsoleteDirectives()
{
$invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
$invoker(function ($file) {
$this->assertNotRegExp('/\\{\\{htmlescape.*?\\}\\}/i', file_get_contents($file), 'Directive {{htmlescape}} is obsolete. Use {{escapehtml}} instead.');
}, \Magento\Framework\App\Utility\Files::init()->getEmailTemplates());
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:7,代码来源:EmailTemplateTest.php
示例11: checkFileContent
protected static function checkFileContent()
{
$fileContent = file_get_contents(static::$tmpFilepath);
// check encoding and convert to utf-8 when necessary
$detectedEncoding = mb_detect_encoding($fileContent, 'UTF-8, ISO-8859-1, WINDOWS-1252', true);
if ($detectedEncoding) {
if ($detectedEncoding !== 'UTF-8') {
$fileContent = iconv($detectedEncoding, 'UTF-8', $fileContent);
}
} else {
echo 'Zeichensatz der CSV-Date stimmt nicht. Der sollte UTF-8 oder ISO-8856-1 sein.';
return false;
}
//prepare data array
$tmpData = str_getcsv($fileContent, PHP_EOL);
array_shift($tmpData);
$preparedData = [];
$data = array_map(function ($row) use(&$preparedData) {
$tmpDataArray = str_getcsv($row, ';');
$tmpKey = trim($tmpDataArray[0]);
array_shift($tmpDataArray);
$preparedData[$tmpKey] = $tmpDataArray;
}, $tmpData);
// generate json
$jsonContent = json_encode($preparedData, JSON_HEX_TAG | JSON_HEX_AMP);
self::$jsonContent = $jsonContent;
return true;
}
开发者ID:antic183,项目名称:php-fileupload-encrypt-json,代码行数:28,代码来源:CsvUploader.php
示例12: doExecute
/**
* Entry point for the script
*
* @return void
*
* @since 1.0
*/
public function doExecute()
{
jimport('joomla.filesystem.file');
if (file_exists(JPATH_BASE . '/configuration.php') || file_exists(JPATH_BASE . '/config.php')) {
$configfile = file_exists(JPATH_BASE . 'configuration.php') ? JPATH_BASE . '/config.php' : JPATH_BASE . '/configuration.php';
if (is_writable($configfile)) {
$config = file_get_contents($configfile);
//Do a simple replace for the CMS and old school applications
$newconfig = str_replace('public $offline = \'0\'', 'public $offline = \'1\'', $config);
// Newer applications generally use JSON instead.
if (!$newconfig) {
$newconfig = str_replace('"public $offline":"0"', '"public $offline":"1"', $config);
}
if (!$newconfig) {
$this->out('This application does not have an offline configuration setting.');
} else {
JFile::Write($configfile, &$newconfig);
$this->out('Site is offline');
}
} else {
$this->out('The file is not writable, you need to change the file permissions first.');
$this->out();
}
} else {
$this->out('This application does not have a configuration file');
}
$this->out();
}
开发者ID:joomlla,项目名称:jacs,代码行数:35,代码来源:TakeOffline.php
示例13: fgetDownload
/**
* @param $url
* @param bool $file
*
* @return bool|null|string
* @throws \Exception
*
* @SuppressWarnings("unused")
*/
public static function fgetDownload($url, $file = false)
{
$return = null;
if ($file === false) {
$return = true;
$file = 'php://temp';
}
$fileStream = fopen($file, 'wb+');
fwrite($fileStream, file_get_contents($url));
$headers = $http_response_header;
$firstHeaderLine = $headers[0];
$firstHeaderLineParts = explode(' ', $firstHeaderLine);
if ($firstHeaderLineParts[1] == 301 || $firstHeaderLineParts[1] == 302) {
foreach ($headers as $header) {
$matches = array();
preg_match('/^Location:(.*?)$/', $header, $matches);
$url = trim(array_pop($matches));
return static::fgetDownload($url, $file);
}
throw new \Exception("Can't get the redirect location");
}
if ($return) {
rewind($fileStream);
$return = stream_get_contents($fileStream);
}
fclose($fileStream);
return $return;
}
开发者ID:designs2,项目名称:composer-client,代码行数:37,代码来源:Downloader.php
示例14: indexAction
/**
* indexAction action.
*/
public function indexAction(Request $request, $_format)
{
$session = $request->getSession();
if ($request->hasPreviousSession() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
// keep current flashes for one more request if using AutoExpireFlashBag
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
}
$cache = new ConfigCache($this->exposedRoutesExtractor->getCachePath($request->getLocale()), $this->debug);
if (!$cache->isFresh()) {
$exposedRoutes = $this->exposedRoutesExtractor->getRoutes();
$serializedRoutes = $this->serializer->serialize($exposedRoutes, 'json');
$cache->write($serializedRoutes, $this->exposedRoutesExtractor->getResources());
} else {
$serializedRoutes = file_get_contents((string) $cache);
$exposedRoutes = $this->serializer->deserialize($serializedRoutes, 'Symfony\\Component\\Routing\\RouteCollection', 'json');
}
$routesResponse = new RoutesResponse($this->exposedRoutesExtractor->getBaseUrl(), $exposedRoutes, $this->exposedRoutesExtractor->getPrefix($request->getLocale()), $this->exposedRoutesExtractor->getHost(), $this->exposedRoutesExtractor->getScheme(), $request->getLocale());
$content = $this->serializer->serialize($routesResponse, 'json');
if (null !== ($callback = $request->query->get('callback'))) {
$validator = new \JsonpCallbackValidator();
if (!$validator->validate($callback)) {
throw new HttpException(400, 'Invalid JSONP callback value');
}
$content = $callback . '(' . $content . ');';
}
$response = new Response($content, 200, array('Content-Type' => $request->getMimeType($_format)));
$this->cacheControlConfig->apply($response);
return $response;
}
开发者ID:kuczek,项目名称:FOSJsRoutingBundle,代码行数:32,代码来源:Controller.php
示例15: execute
public function execute($url, $data = null)
{
if ($this->artificialDelay > 0) {
sleep($this->artificialDelay);
}
return file_get_contents(__DIR__ . '/USPSResponse.xml');
}
开发者ID:dlashua,项目名称:shipping,代码行数:7,代码来源:StubUSPS.php
示例16: getLiveScore
public static function getLiveScore($requester, $request)
{
$requestParams = explode(",", $request);
$scoreAvailable = false;
$team1 = $requestParams[0];
$team2 = $requestParams[1];
$matchList = file_get_contents(self::$cricInfoURL);
$message = "Sorry, this match information is not available.";
if ($matchList) {
$json = json_decode($matchList, true);
foreach ($json as $value) {
echo $value['t1'] . '/n';
echo $value['t2'] . '/n/n';
if ((stripos($value['t1'], $team1) > -1 || stripos($value['t1'], $team2) > -1) && (stripos($value['t2'], $team1) > -1 || stripos($value['t2'], $team2) > -1)) {
$matchScoreURL = self::$cricInfoURL . '?id=' . $value['id'];
$matchScore = file_get_contents($matchScoreURL);
$matchScore = json_decode($matchScore, true);
$score = $matchScore['0']['de'];
$scoreAvailable = true;
MessaggingController::sendMessage($requester, $score);
}
}
} else {
$message = "Service temporarily not available, please try after some time";
}
if (!$scoreAvailable) {
MessaggingController::sendMessage($requester, $message);
}
PubSub::publish(GenieConstants::$SERVICE_REQUEST_COMPLETE, $requester);
}
开发者ID:neerav-mehta,项目名称:yboocs,代码行数:30,代码来源:Cricket.php
示例17: GetCounter
function GetCounter()
{
if (file_exists(COUNTER_FILE)) {
return intval(file_get_contents(COUNTER_FILE));
}
return 0;
}
开发者ID:ratan203,项目名称:phpsyntaxtree,代码行数:7,代码来源:counter.php
示例18: buildJavascriptConfiguration
/**
* Return JS configuration of the htmlArea plugins registered by the extension
*
* @return string JS configuration for registered plugins
*/
public function buildJavascriptConfiguration()
{
$schema = array('types' => array(), 'properties' => array());
// Parse configured schemas
if (is_array($this->configuration['thisConfig']['schema.']) && is_array($this->configuration['thisConfig']['schema.']['sources.'])) {
foreach ($this->configuration['thisConfig']['schema.']['sources.'] as $source) {
$fileName = trim($source);
$absolutePath = GeneralUtility::getFileAbsFileName($fileName);
// Fallback to default schema file if configured file does not exists or is of zero size
if (!$fileName || !file_exists($absolutePath) || !filesize($absolutePath)) {
$fileName = 'EXT:' . $this->extensionKey . '/Resources/Public/Rdf/MicrodataSchema/SchemaOrgAll.rdf';
}
$fileName = $this->getFullFileName($fileName);
$rdf = file_get_contents($fileName);
if ($rdf) {
$this->parseSchema($rdf, $schema);
}
}
}
uasort($schema['types'], array($this, 'compareLabels'));
uasort($schema['properties'], array($this, 'compareLabels'));
// Insert no type and no property entries
$languageService = $this->getLanguageService();
$noSchema = $languageService->sL('LLL:EXT:rtehtmlarea/Resources/Private/Language/Plugins/MicrodataSchema/locallang.xlf:No type');
$noProperty = $languageService->sL('LLL:EXT:rtehtmlarea/Resources/Private/Language/Plugins/MicrodataSchema/locallang.xlf:No property');
array_unshift($schema['types'], array('name' => 'none', 'label' => $noSchema));
array_unshift($schema['properties'], array('name' => 'none', 'label' => $noProperty));
// Store json encoded array in temporary file
return 'RTEarea[editornumber].schemaUrl = "' . $this->writeTemporaryFile('schema_' . $this->configuration['language'], 'js', json_encode($schema)) . '";';
}
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:35,代码来源:MicroDataSchema.php
示例19: getElementsData
function getElementsData() {
$elements_dirname = ADMIN_BASE_PATH.'/components/elements';
if ($elements_dir = opendir($elements_dirname)) {
$tmpArray = array();
while (false !== ($dir = readdir($elements_dir))) {
if (substr($dir,0,1) != "." && is_dir($elements_dirname . '/' . $dir)) {
$tmpKey = strtolower($dir);
if (@file_exists($elements_dirname . '/' . $dir . '/metadata.json')) {
$tmpValue = json_decode(@file_get_contents($elements_dirname . '/' . $dir . '/metadata.json'));
if ($tmpValue) {
$tmpArray["$tmpKey"] = $tmpValue;
}
}
}
}
closedir($elements_dir);
if (count($tmpArray)) {
return $tmpArray;
} else {
return false;
}
} else {
echo 'not dir';
return false;
}
}
开发者ID:GabeGibitz,项目名称:DIY,代码行数:26,代码来源:helpers.php
示例20: index
function index()
{
$path = \GCore\C::get('GCORE_ADMIN_PATH') . 'extensions' . DS . 'chronoforms' . DS;
$files = \GCore\Libs\Folder::getFiles($path, true);
$strings = array();
//function to prepare strings
$prepare = function ($str) {
/*$path = \GCore\C::get('GCORE_FRONT_PATH');
if(strpos($str, $path) !== false AND strpos($str, $path) == 0){
return '//'.str_replace($path, '', $str);
}*/
$val = !empty(\GCore\Libs\Lang::$translations[$str]) ? \GCore\Libs\Lang::$translations[$str] : '';
return 'const ' . trim($str) . ' = "' . str_replace("\n", '\\n', $val) . '";';
};
foreach ($files as $file) {
if (substr($file, -4, 4) == '.php') {
// AND strpos($file, DS.'extensions'.DS) === TRUE){
//$strings[] = $file;
$file_code = file_get_contents($file);
preg_match_all('/l_\\(("|\')([^(\\))]*?)("|\')\\)/i', $file_code, $langs);
if (!empty($langs[2])) {
$strings = array_merge($strings, $langs[2]);
}
}
}
$strings = array_unique($strings);
$strings = array_map($prepare, $strings);
echo '<textarea rows="20" cols="80">' . implode("\n", $strings) . '</textarea>';
}
开发者ID:ejailesb,项目名称:repo_empr,代码行数:29,代码来源:langs.php
注:本文中的file_get_contents函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论