本文整理汇总了PHP中parse_file函数的典型用法代码示例。如果您正苦于以下问题:PHP parse_file函数的具体用法?PHP parse_file怎么用?PHP parse_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: open_from_client
/**
* @return String/FALSE on error
* @desc Writes and uploaded file into a temp file and returns the name of that file for future
* use. Returns false if there is an error.
*/
function open_from_client()
{
global $javascript_msg;
// Create a temporary file where we will copy the uploaded one to
$temp_file = 'temp/' . date('YmdHis') . '.wp';
if ($local_file = @fopen($temp_file, 'w')) {
// Make sure that the file parsing function exists, or grab code for it
if (!function_exists('parse_file')) {
require_once 'common.php';
}
// Get the uploaded file, open it, then write it into the temp file
if ($uploaded = parse_file($_FILES['file']['tmp_name'])) {
@fwrite($local_file, $uploaded);
fclose($local_file);
// Return the name of the temp file for use in opening (from server now)
return $temp_file;
} else {
$javascript_msg = '@Could not read \'' . $temp_file . '\' or it is empty.';
return false;
}
} else {
$javascript_msg = '@Could not create temporary file. Check the permissions on webpad\'s temporary folder.';
return false;
}
}
示例2: compile_markdown_files_metadata
function compile_markdown_files_metadata($folder, $output_file)
{
$data = array();
foreach (file_list($folder) as $file) {
$data[$file] = parse_file($file);
$data[$file]['link'] = generate_link($file);
unset($data[$file]['content']);
}
$data_before = <<<EOT
<?php
/*
===== This file is auto-generated. It contains the compiled metadata from the markdown. =====
*/
function compiled_metadata(\$file = null) {
\$data =
EOT;
$data_after = <<<EOT
;
\tif (\$file == null || !isset(\$data[\$file])) {
\t\treturn \$data;
\t} else {
\t\treturn \$data[\$file];
\t}
}
EOT;
$complete_data = $data_before . var_export($data, true) . $data_after;
$file_handle = fopen($output_file, "w");
if ($file_handle == false) {
die('Could not open compiled file to write.');
}
if (!fwrite($file_handle, $complete_data)) {
die('Could not write to file');
}
}
示例3: movies_storing
function movies_storing($db, $filename = "movies.csv")
{
if (check_file($filename)) {
$collection = $db->createCollection("movies");
$i = parse_file($collection, get_data($filename));
echo $i . " movies successfully stored !\n";
}
}
示例4: open_from_http
/**
* @return String/FALSE on error
* @param String $url
* @desc Attempts to request a URL and parse the response into a string, which is opened as a file.
*/
function open_from_http($url)
{
global $javascript_msg;
// Make sure this is a valid URL
if (strpos($url, 'http://') === false) {
$javascript_msg = '@Invalid URL. Please enter a full web address, starting with http://';
return false;
}
// Make sure that the file parsing function exists, or grab code for it
if (!function_exists('parse_file')) {
require_once 'common.php';
}
// Now parse the URL and get it as a string
if ($contents = parse_file($url)) {
return $contents;
} else {
$javascript_msg = '@Could not load \'' . stripslashes($url) . '\'.';
return false;
}
}
示例5: display_patch_list
function display_patch_list($title, $patchdir)
{
global $ADMIN_TYPE;
echo "<h3>" . $title . "</h3>";
$filelist = get_file_list('./admin/patch_facility/sql/' . $patchdir, 'sql');
$sqllist = NULL;
if (is_not_empty_array($filelist)) {
for ($i = 0; $i < count($filelist); $i++) {
$parsedfile_r = parse_file($filelist[$i]);
$sqllist[] = array('sqlfile' => $filelist[$i], 'name' => initcap(str_replace('_', ' ', $parsedfile_r['name'])));
}
if (is_not_empty_array($sqllist)) {
echo "<table>";
echo "<tr class=\"navbar\">" . "<th>Patch</th>" . "<th>SQL File</th>" . "<th></th>" . "<th></th>" . "</tr>";
for ($i = 0; $i < count($sqllist); $i++) {
echo "<tr class=\"oddRow\">" . "<td>" . $sqllist[$i]['name'] . "</td>" . "<td>" . $sqllist[$i]['sqlfile'] . "</td>" . "<td><a href=\"admin.php?type={$ADMIN_TYPE}&op=previewsql&mode=job&title=" . urlencode($sqllist[$i]['sqlfile']) . "&patchdir={$patchdir}&sqlfile=" . $sqllist[$i]['sqlfile'] . "&preview=true\" target=\"_new\">Preview</a></td>" . "<td><a href=\"admin.php?type={$ADMIN_TYPE}&op=installsql&patchdir={$patchdir}&sqlfile=" . $sqllist[$i]['sqlfile'] . "\">Install</a></td>" . "</tr>";
}
echo "</table>";
}
}
}
示例6: open_from_ftp
/**
* @return String/FALSE on error
* @param String $server
* @param String $port
* @param String $pasv
* @param String $username
* @param String $password
* @param String $file
* @desc Connects to an FTP server, requests the specified file, writes it to
* a temporary location and then loads it into a string.
*/
function open_from_ftp($server, $port = '', $pasv, $username, $password, $file)
{
global $javascript_msg;
// Set the port we're using
$port = isset($port) && $port != '' ? $port : 0;
// Connect to FTP Server
if ($ftp = @ftp_connect($server, $port)) {
// Log in using details provided
if ($logged_in = @ftp_login($ftp, $username, $password)) {
// Set PASV mode
ftp_pasv($ftp, $pasv);
// Create a temporary file, and get the remote file contents into it.
$temp_file = 'temp/' . date('YmdHis') . '.wp';
if ($local_file = @fopen($temp_file, 'wt')) {
if (@ftp_fget($ftp, $local_file, $file, FTP_ASCII)) {
@ftp_quit($ftp);
fclose($local_file);
// Make sure that the file parsing function exists, or grab code for it
if (!function_exists('parse_file')) {
require_once 'common.php';
}
$string = parse_file($temp_file);
return $string;
} else {
$javascript_msg = '@Could not get the file from the FTP Server.';
return false;
}
} else {
$javascript_msg = '@Could not create temporary file. Check the permissions on webpad\'s temporary folder.';
return false;
}
} else {
$javascript_msg = '@Authentication failed on FTP Server \'' . $server . '\'.';
return false;
}
} else {
$javascript_msg = '@Could not connect to FTP Server \'' . $server . '\'.';
return false;
}
}
示例7: open_from_server
/**
* @return String/FALSE on error
* @param String $file
* @desc Parses a file and returns it as a string.
*/
function open_from_server($file)
{
global $javascript_msg, $config;
// Confirm we should be opening this, or die
verify_secure_file($file, $config['home_dir']);
// Make sure that the file parsing function exists, or grab code for it
if (!function_exists('parse_file')) {
require_once 'common.php';
}
// Get the file and return it if we can
$contents = parse_file($file);
// If there's something there (even if it's an empty string)
if ($contents !== false) {
$javascript_msg = 'File opened successfully.';
return $contents;
} else {
$javascript_msg = '@Could not open file \'' . stripslashes(basename($file)) . '\'.';
$_SESSION['filename'] = '';
$_SESSION['display_filename'] = '';
return false;
}
}
示例8: redirect
redirect($url, $lang_uploadile['err_delete']);
}
} elseif (isset($_FILES['fichier']) and $_FILES['fichier'] != NULL and $_FILES['fichier']['error'] == 0) {
// On vérifie les extansions
$extension_multiple = explode('.', $_FILES['fichier']['name']);
if (count($extension_multiple) == '2') {
$extensions_valides = explode(',', $pun_config['o_uploadile_laws'] . ',' . strtoupper($pun_config['o_uploadile_laws']));
$extension_upload = substr(strrchr($_FILES['fichier']['name'], '.'), 1);
if (in_array($extension_upload, $extensions_valides)) {
// On vérifie la taille maximale
if ($_FILES['fichier']['size'] <= $maxsize) {
// On vérifie l'espace alloué
if ($_FILES['fichier']['size'] + $user_plugile['upload'] <= $limit) {
$upload = $user_plugile['upload'] + $_FILES['fichier']['size'];
$fichier = explode('.', $_FILES['fichier']['name']);
$fichier = parse_file($fichier[0]) . '.' . $fichier[1];
$fichier_name_temp = $_FILES['fichier']['tmp_name'];
$dir = 'img/members/' . $id . '/';
if (is_file($dir . $fichier)) {
$fichier = date('dmY\\-Hi', time()) . '_' . $fichier;
}
if (!is_dir('img/members/')) {
mkdir('img/members', 0755);
}
if (!is_dir($dir)) {
mkdir('img/members/' . $id, 0755);
}
move_uploaded_file($fichier_name_temp, $dir . $fichier);
// Miniaturisation des images si demandées
if ($pun_config['o_uploadile_thumb'] == '1') {
$hauteur_destination = $pun_config['o_uploadile_thumb_size'];
示例9: get_reports
function get_reports(&$reports, &$files)
{
global $start_date;
global $end_date;
note("Starting file requests.");
// Work through reports until we have pulled all of them
foreach ($reports as $index => $report) {
$json = get_json($report['request']['@reportUri']);
if ($json['@reportReady'] != "false") {
//Set report file name
$report_file = "{$REPORT}/" . "report_" . $report['ref_name'] . "_" . $end_date . ".gz";
// Get the report
$file = get_file($report['request']['@reportUri'], $report_file);
note("Got file {$file} for Game: " . $report['game_id'] . ", Client: " . $report['client_id']);
// Are we writing this to a CSV?
if (!array_key_exists('x', $options)) {
// Write to a CSV file - split sessions and events
$output_file_sessions = "{$CSV}/" . $report['ref_name'] . "_" . $end_date . '_sessions.csv';
$output_file_events = "{$CSV}/" . $report['ref_name'] . "_" . $end_date . '_events.csv';
$fhs = fopen($output_file_sessions, 'w') or die("ERROR: Could not open session output file.\n");
$fhe = fopen($output_file_events, 'w') or die("ERROR: Could not open events output file.\n");
note("File {$file} parsing started for Game: " . $report['game_id'] . ", Client: " . $report['client_id'] . " from {$start_date} to {$end_date}.");
$rc = parse_file($file, $report['game_id'], $report['client_id'], $options);
// Remove this entry
if ($rc != FALSE) {
note("File {$file} parsing complete for Game: " . $report['game_id'] . ", Client: " . $report['client_id'] . " from {$start_date} to {$end_date}.");
$files[] = array('game_id' => $report['game_id'], 'client_id' => $report['client_id'], 'file' => $file);
unset($reports[$index]);
}
fclose($fhs);
fclose($fhe);
} else {
note("File {$file} was not parsed for Game: " . $report['game_id'] . ", Client: " . $report['client_id'] . " from {$start_date} to {$end_date}.");
unset($reports[$index]);
}
} else {
note("File not ready for Game: " . $report['game_id'] . ", Client: " . $report['client_id'] . " from {$start_date} to {$end_date}.");
}
}
}
示例10: header
<?php
require_once 'admin/configuration.php';
require_once 'admin/authentication.php';
require_once 'locations/common.php';
// Send headers to force a named file download
header('Content-disposition: attachment; filename="' . urldecode($_REQUEST['f']) . '"');
// If the file exists, dump the contents
if (is_file('temp/' . urldecode($_REQUEST['t']))) {
// Get temp file
$str = parse_file('temp/' . urldecode($_REQUEST['t']));
// Fix linebreaks for destination
// Windows
if (stristr($_SERVER['HTTP_USER_AGENT'], 'win') !== false) {
$str = str_replace("\n", "\r\n", $str);
} else {
if (stristr($_SERVER['HTTP_USER_AGENT'], 'mac') !== false) {
$str = str_replace("\n", "\r", $str);
}
}
// Others can stay with \n
echo $str;
}
exit;
示例11: import_exercise
/**
* Imports an exercise in QTI format if the XML structure can be found in it
* @param array $file
* @return an array as a backlog of what was really imported, and error or debug messages to display
*/
function import_exercise($file)
{
global $exercise_info;
global $element_pile;
global $non_HTML_tag_to_avoid;
global $record_item_body;
// used to specify the question directory where files could be found in relation in any question
global $questionTempDir;
$archive_path = api_get_path(SYS_ARCHIVE_PATH) . 'qti2';
$baseWorkDir = $archive_path;
if (!is_dir($baseWorkDir)) {
mkdir($baseWorkDir, api_get_permissions_for_new_directories(), true);
}
$uploadPath = '/';
// set some default values for the new exercise
$exercise_info = array();
$exercise_info['name'] = preg_replace('/.zip$/i', '', $file);
$exercise_info['question'] = array();
$element_pile = array();
// create parser and array to retrieve info from manifest
$element_pile = array();
//pile to known the depth in which we are
//$module_info = array (); //array to store the info we need
// if file is not a .zip, then we cancel all
if (!preg_match('/.zip$/i', $file)) {
return 'UplZipCorrupt';
}
// unzip the uploaded file in a tmp directory
if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) {
return 'UplZipCorrupt';
}
// find the different manifests for each question and parse them.
$exerciseHandle = opendir($baseWorkDir);
//$question_number = 0;
$file_found = false;
$operation = false;
$result = false;
$filePath = null;
// parse every subdirectory to search xml question files
while (false !== ($file = readdir($exerciseHandle))) {
if (is_dir($baseWorkDir . '/' . $file) && $file != "." && $file != "..") {
// Find each manifest for each question repository found
$questionHandle = opendir($baseWorkDir . '/' . $file);
while (false !== ($questionFile = readdir($questionHandle))) {
if (preg_match('/.xml$/i', $questionFile)) {
$result = parse_file($baseWorkDir, $file, $questionFile);
$filePath = $baseWorkDir . $file;
$file_found = true;
}
}
} elseif (preg_match('/.xml$/i', $file)) {
// Else ignore file
$result = parse_file($baseWorkDir, '', $file);
$filePath = $baseWorkDir . '/' . $file;
$file_found = true;
}
}
if (!$file_found) {
return 'NoXMLFileFoundInTheZip';
}
if ($result == false) {
return false;
}
$doc = new DOMDocument();
$doc->load($filePath);
$encoding = $doc->encoding;
// 1. Create exercise.
$exercise = new Exercise();
$exercise->exercise = $exercise_info['name'];
$exercise->save();
$last_exercise_id = $exercise->selectId();
if (!empty($last_exercise_id)) {
// For each question found...
foreach ($exercise_info['question'] as $question_array) {
//2. Create question
$question = new Ims2Question();
$question->type = $question_array['type'];
$question->setAnswer();
$question->updateTitle(formatText($question_array['title']));
//$question->updateDescription($question_array['title']);
$type = $question->selectType();
$question->type = constant($type);
$question->save($last_exercise_id);
$last_question_id = $question->selectId();
//3. Create answer
$answer = new Answer($last_question_id);
$answer->new_nbrAnswers = count($question_array['answer']);
$totalCorrectWeight = 0;
foreach ($question_array['answer'] as $key => $answers) {
$split = explode('_', $key);
$i = $split[1];
// Answer
$answer->new_answer[$i] = formatText($answers['value']);
// Comment
$answer->new_comment[$i] = isset($answers['feedback']) ? formatText($answers['feedback']) : null;
//.........这里部分代码省略.........
示例12: file_get_contents
</p>
<h2>Source</h2>
<p>If you click <a href="<?php
echo $_SERVER['PHP_SELF'] . "?source";
?>
">here</a> you will see the source of the <tt>parse_file()</tt> and the helper function <tt>tidyline()</tt>.
</p>
<h2>Parsed file follows:</h2>
<?php
require_once 'parse.php';
$file = "Inverza280.spm";
$fileContents = file_get_contents($file);
/*
* Call parse_file, which does the heavy lifting of parsing
* the file, then pass the output to json_encode to output
* a json interpretation of the file, then to print_r to
* dump the json to the browser
*
* Note: JSON_PRETTY_PRINT requires php 5.4.0 or higher but
* is only needed to make the output more human readable
*/
echo '<pre>';
print_r(json_encode(parse_file($fileContents), JSON_PRETTY_PRINT));
echo '</pre>';
?>
<hr>
<p>End of file</p>
</body>
</html>
示例13: show_register
function show_register($d)
{
global $dir, $files, $cats, $names, $PAGE, $DATA, $this_page, $link;
$d = "{$dir}/regmem{$d}.xml";
if (!in_array($d, $files)) {
$d = $files[0];
}
$d_iso = preg_replace("#{$dir}/regmem(.*?)\\.xml#", '$1', $d);
$d_pretty = format_date($d_iso, LONGDATEFORMAT);
$d = file_get_contents($d);
$data = array();
parse_file($d, 'only', $data);
$this_page = 'regmem_date';
$DATA->set_page_metadata($this_page, 'heading', "The Register of Members' Interests, {$d_pretty}");
$PAGE->stripe_start();
print $link;
?>
<p>This page shows the Register of Members' Interests as released on <?php
echo $d_pretty;
?>
, in alphabetical order by MP.
<?php
if ($d_iso > '2002-05-14') {
?>
<a href="./?f=<?php
echo $d_iso;
?>
">Compare this edition with the one before it</a></p><?php
}
?>
<div id="regmem">
<?php
uksort($data, 'by_name_ref');
foreach ($data as $person_id => $v) {
$out = '';
foreach ($v as $cat_type => $vv) {
$out .= cat_heading($cat_type, false);
$d = array_key_exists('only', $data[$person_id][$cat_type]) ? $data[$person_id][$cat_type]['only'] : '';
$out .= prettify($d) . "\n";
}
if ($out) {
print '<div class="block">';
print '<h2><a name="' . $person_id . '"></a>' . $names[$person_id] . ' - ';
print '<a href="?p=' . $person_id . '">Register history</a> | ';
print '<a href="http://www.theyworkforyou.com/mp/?pid=' . $person_id . '">MP\'s page</a>';
print '</h2> <div class="blockbody">';
print "\n{$out}";
print '</div></div>';
}
}
print '</div>';
}
示例14: parse_file
<?php
function parse_file($file)
{
/**
* Grabing contents from file
*/
$handle = fopen($file, 'r');
$content = fread($handle, filesize($file));
$content = trim($content);
fclose($handle);
/**
* splitting the string into an array of lines
* Removing first line on title from the array
*/
$content_lines = explode(PHP_EOL, $content);
array_shift($content_lines);
/**
* Explode the lines of content into an tempary info array.
*
* Use the temaray info array to create an associatave array and push onto parks
*/
$parks_array = [];
foreach ($content_lines as $line) {
$info_array = explode('","', $line);
$parks_array[] = ['name' => substr($info_array[0], 1), 'location' => $info_array[2], 'date_established' => date("Y-m-d", strtotime($info_array[3])), 'area' => $info_array[4], 'description' => substr($info_array[6], 0, -1)];
}
return $parks_array;
}
$parks_array = parse_file('parks.csv');
// print_r($parks_array[0]);
示例15: explode
if (is_integer($key) && $key != 0) {
$to_use_multi[] = $val;
}
}
} else {
$to_use_multi = explode(':', $_to_use);
}
}
foreach ($to_use_multi as $to_use) {
// $to_use=str_replace('\\','/',$to_use);
$full_path = ($OCPORTAL_PATH == '' ? '' : $OCPORTAL_PATH . (substr($OCPORTAL_PATH, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR)) . $to_use;
if (strpos(file_get_contents($full_path), '/*CQC: No check*/') !== false) {
echo 'SKIP: ' . $to_use . cnl();
continue;
}
check(parse_file($full_path));
}
}
echo 'FINAL Done!';
// Do the actual code quality check
function check($structure)
{
global $GLOBAL_VARIABLES, $CURRENT_CLASS, $OK_EXTRA_FUNCTIONS;
$GLOBAL_VARIABLES = array();
$OK_EXTRA_FUNCTIONS = $structure['ok_extra_functions'];
$CURRENT_CLASS = '__global';
global $LOCAL_VARIABLES;
$LOCAL_VARIABLES = reinitialise_local_variables();
if ($GLOBALS['OK_EXTRA_FUNCTIONS'] == '') {
foreach ($structure['functions'] as $function) {
if ($GLOBALS['OK_EXTRA_FUNCTIONS'] != '') {