PHP Files functions
Posted Coding_Changes_LIfe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Files functions相关的知识,希望对你有一定的参考价值。
simple functions
<?php
$docRoot = $_SERVER['DOCUMENT_ROOT'];
//readfile($docRoot."/orders/order.txt"); //do not need fopen
unlink($docRoot."/orders/order.txt");
$fp = fopen($docRoot."/orders/orders.txt",rb);
if($fp){
echo "open ok";
}else{
echo 'error';
}
while (!feof($fp)){
echo fgetc($fp);
}
//fpassthru($fp); //out put string needs fopen
//$len = fwrite($fp,'12345',3);
rewind($fp);
fseek();
fclose($fp);
//file_put_contents($docRoot/orders/order.txt,'123',FILE_APPEND);
Examples
<?php
// create short variable name
$document_root = $_SERVER['DOCUMENT_ROOT'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
@$fp = fopen("$document_root/orders/Book1.csv", 'rb');
flock($fp, LOCK_SH); // lock file for reading
if (!$fp) {
echo "<p><strong>No orders pending.<br />
Please try again later.</strong></p>";
exit;
}
while (!feof($fp)) {
$order= fgets($fp);
echo htmlspecialchars($order)."<br />";
}
flock($fp, LOCK_UN); // release read lock
echo 'Final position of the file pointer is '.(ftell($fp));
echo '<br />';
rewind($fp);
echo 'After rewind, the position is '.(ftell($fp));
echo '<br />';
// while (!feof($fp)) {
//
// $s= fgetcsv($fp,9,',');
// echo "<pre>";
// var_dump($s);
// }
if(is_null($s)) {
echo 'null';
}
fclose($fp);
?>
</body>
</html>
以上是关于PHP Files functions的主要内容,如果未能解决你的问题,请参考以下文章
php Wordpress functions.php片段使用Yoast的插件将Google Analytics跟踪添加到wp_nav_menu
Choose unique values for the 'webAppRootKey' context-param in your web.xml files! 错误的解决(代码片段