我现在已经看了很长一段时间,看看如果使用带有PHP的ob_start,是否可以"附加"到文件中.
我尝试了以下但没有奏效.有没有实现这个目标?
<?php
$cacheFile = 'file.txt';
if ( (file_exists($cacheFile)) && ((fileatime($cacheFile) + 600) > time()) )
{
$content = file_get_contents($cacheFile);
echo $content;
} else
{
ob_start();
// write content
echo '<h1>Hello world</h1>';
$content = ob_get_contents();
ob_end_clean();
file_put_contents($cacheFile,$content,'a+'); // I added the a+
echo $content;
}
?>
Run Code Online (Sandbox Code Playgroud)
我从SO的另一篇文章中借用了上面的例子
我从SO上提出的另一个问题中借用了一些代码,因为我找不到一个可以实现我想要实现的脚本.
我想要做的是根据分配的日期突出显示当前事件,以下代码不适用于<td>表,元素<div>或<p>元素中的元素.
我还想将亮点应用于同名的任何ID,这可能与我现在拥有的一样吗?
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>
<style>
body {padding: 20px; font-family: sans-serif;}
p {margin-top: 80px; font-size: 11px;}
.active {color: hotpink;
background:#000;
font-weight:bold;
}
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
var TODAY = new Date();
//Individual dates could be organized as objects, but using arrays below seems to be more readable and tidy
var SCHEDULE = {
'some-class': ['May 5 2011', 'June 5 2011'],
'some-class-a': ['May 5 2012', 'June …Run Code Online (Sandbox Code Playgroud) 例如,我有以下代码:
$sample = array(apple, orange, banana, grape);
Run Code Online (Sandbox Code Playgroud)
我想通过创建$sample[2]new来重新排列这个数组,$sample[0]同时在整个数组中保持相同的顺序。
输出应该是:
Array ( [0] => banana [1] => grape [2] => apple [3] => orange)
Run Code Online (Sandbox Code Playgroud) 我是新来的.
无论如何,我对fwrite()进行了研究,但是我找不到解决方案,所以我正在寻求帮助.我想要的是在一些其他特定的行之后添加一行新的文本.我有一个.txt文件,其中有:
//Users
//Other stuff
//Other stuff2
Run Code Online (Sandbox Code Playgroud)
现在我想做的是能够在//用户下面添加一个新用户而不用触及"其他东西"和"其他东西2".所以看起来应该是这样的:
//Users
Aneszej
Test321
Test123
//Other stuff
//Other stuff2
Run Code Online (Sandbox Code Playgroud)
到目前为止我所拥有的:
$config = 'test.txt';
$file=fopen($config,"r+") or exit("Unable to open file!");
$date = date("F j, Y");
$time = date("H:i:s");
$username = "user";
$password = "pass";
$email = "email";
$newuser = $username . " " . $password . " " . $email . " " . $date . " " . $time;
while (!feof($file)) {
$line=fgets($file);
if (strpos($line, '//Users')!==false) {
$newline = PHP_EOL . $newuser;
} …Run Code Online (Sandbox Code Playgroud) 好的,我希望我的用户能够下载.txt带有用户名的文件.
我到处检查,到目前为止,我无法找到我想要的,或者如果它甚至有可能.
为了举例说明我正在尝试做的事情,这是我的代码:
<button type="button">Download All Your Keys On A .txt
<?php
$file = 'logs/$session->username.txt';
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
$type = filetype($file); // Get a date and timestamp $today = date("F j, Y, g:i a"); $time = time(); // Send file headers header("Content-type: $type"); header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0'); // Send the file contents.
set_time_limit(0);
readfile($file);
?>
</button>
Run Code Online (Sandbox Code Playgroud)
我正在尝试这样做,以便当您单击按钮时,它会强制下载配置为的.txt文件:
$file = 'logs/$session->username.txt';
Run Code Online (Sandbox Code Playgroud)
对不起,如果这令人困惑和混乱,但没有其他方式让我提出这个.
提前致谢!
我对php/mysql的工作量不大,但我需要的是一个相对简单的任务:检查表是否存在,如果不存在则创建表.我甚至无法获得有用的错误消息,并且数据库中没有创建表.我的语法显然有问题.
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
// 1. CONNECT TO THE DB SERVER, confirm connection
mysql_connect("localhost", "root", "") or die(mysql_error());
echo "<p>Connected to MySQL</p>";
$mysql_connexn = mysql_connect("localhost", "root", ""); // redundant ?
// 2. CONNECT TO THE SPECIFIED DB, confirm connection
$db = "weighttracker";
mysql_select_db($db) or die(mysql_error());
echo "<p>Connected to Database '$db'</p>";
$db_connexn = mysql_select_db($db)or die(mysql_error("can\'t connect to $db"));
// 3. if table doesn't exist, create it
$table = "WEIGHIN_DATA";
$query = "SELECT ID FROM " . $table;
//$result = …Run Code Online (Sandbox Code Playgroud) 我已经连接到数据库了.当我回显所有变量时,它们可以工作,但它们不会插入到我的数据库表中.我的表名正确.这是代码:
<?php
$pid = '1';
$pname = 'name';
$poster_id = '2';
$poster_name = 'name2';
$message = 'This is the message';
$datetime = date("M d, Y");
// insert into database
$ins = "INSERT INTO messages (profile_id, profile_name, poster_id, poster_name, message, countnum, postdate) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $con->prepare($ins);
$num = 1;
$stmt->bind_param('isissis', $pid, $pname, $user_id, $user, $comment, $num, $datetime);
$stmt->execute();
?>
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助.
java -jar tika-app-1.10-SNAPSHOT.jar -m manu.pdf > output.txt它成功地在输出文件中创建了我需要的文本。从 PHP 调用 Tika 以便将上传文件的纯文本导入 PHP 的最佳方法是什么?
环顾四周,我发现:
exec命令调用 Tika 。但我不确定什么是最简单的方法。
我试图使用PHP显示从表中的数据库检索到的图像,到目前为止这是成功的.但是,我的一些文字描述太长,并且比单个缩略图更长.
如您所见,"会计"字太长了.我想设置要在图像边框内设置的文本,所有图像的宽度都是350像素.如果它有帮助,这些是我的表的PHP代码.
echo "<table width = '100%' height ='100%'><tr>";
$rows_fetched = - 1;
while ($stmt->fetch()) {
$rows_fetched++;
if ($rows_fetched <= 2) {
echo "<td width = '350px'height = '100%'>";
echo "<a href='video-page.php'> <img src='$thumbnail' alt='' width='350px' height='200px'>";
echo "<h4>$title</h4>";
// echo "<h4> hi </h4>";
echo "</td>";
} else {
echo "</tr>";
echo "<tr>";
echo "<td width = '350px' height ='100%' >";
echo "<a class href='video-page.php'> <img src='$thumbnail' alt='' width='350px' height='200px'>";
echo "<h4 class ='img-with-text'>$title</h4>";
// echo "<h4> hi …Run Code Online (Sandbox Code Playgroud) 目前,我正在为我的广告目标网页生成一个随机数,以弥补正在使用的MB,并且它运行良好.
但我想知道我是否有可能以某种方式获得每次生成的相同数字,<?php echo(rand(10,20)); ?>因此我可以在多个位置使用它.