大家早,
我有一个我一直在测试的PHP脚本,当我从命令行调用它时似乎运行正常.
我现在想通过cron自动化它,如何将我作为检查点放入文件的输出到日志文件中?
例如,我在脚本中有一些简单的echo命令,我希望输出显示在现有的日志文件中(以便它自动旋转等)
谢谢,
格雷格
我正在使用http://validator.w3.org验证我的网站,并且&在我的链接描述文本中有一个问题.
这取自来源:
<a class='tag' href='/php/iphone software.php?function=developer&dev=witch%26wizards+inc.&store=143441'>witch&wizards inc.</a>
Run Code Online (Sandbox Code Playgroud)
这会在验证器中出现此错误:
第188行,第540列:无法生成一般实体"向导"的系统标识符
... 6wizards + inc.&store = 143441'> witch&wizards inc.
✉在文档中找到了实体引用,但没有定义该名称的引用
如果我对该描述进行了urlencode,那么验证就会通过,但是用户会看到文本显示为urlencoded,即
开发者女巫%26wizards + inc.
但是,如果显示未编码,即我认为它更加用户友好
开发者巫师和巫师公司
有没有办法通过验证,但仍然显示用户友好的文本?
我试图读取XML文件并将其与现有数据库中的字段进行比较.
如果XML文件中不存在数据库中的ID,则与Id对应的整行不再有效,将被删除.
为此,我在while语句中从头到尾读取XML的每一行.
作为第一步,我尝试进行简单的比较,如果在数据库中找到XML中不存在的Id,则回显.
我知道数据库中有一些ID不存在于XML中,但下面的代码没有显示它们.
我有三个问题,首先是如何显示从数据库中提取的Id,其次是为什么这段代码找不到XML中没有的任何ID?
最后一个问题是,我是以完全错误的方式解决这个问题,并且有更好的方法来做到这一点!
$sql_result = mysql_query("SELECT id FROM `list` WHERE id = $id") or die(mysql_error());
if($sql_result)
{
// echo $id . " Id exists " . $sql_result["id"] . "\n";
}
else
{
echo "Id no longer exists" . $id . "\n";
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试对从旧子域到新域的所有内容进行301重定向.
我有一个简单的.htaccess
Redirect 301 / http://www.smartphonesoft.com/
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用子目录转到旧URL,它会尝试使用子目录重定向到新域并失败.
即
http://forum.smartphonesoft.com/reminder/
去
http://www.smartphonesoft.com/reminder/
当我希望它转到
http://www.smartphonesoft.com/
如何将所有内容简单地重定向到新的域根目录?
早上好,
我正在尝试使用以下代码将字符串传递给twitter
// The message you want to send
$message = "http://www.smartphonesoft.com/index.php?option=com_mtree&task=viewlink&link_id=" .$link_id . " " ."Android Software" . " " .$link_name . " " . $metadesc;
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
Run Code Online (Sandbox Code Playgroud)
然而,在twitter上出现的所有内容都是链接
我正在将大量信息从XML文件写入数据库.
一切正常,直到我遇到一个带有'在描述中的字段,插入失败并出现错误
Run Code Online (Sandbox Code Playgroud)Error 1064:You have an error in your SQL syntax; check the manual that对应你的MySQL服务器版本,使用正确的语法,让你感觉就像这样.我们很乐意让您访问我们,在第3行查看超过100'
有没有办法插入它而不失败?导入文件可能很大并且会定期更改,因此我无法搜索和替换其中的字符.
我的实际PHP声明是:
$query = mysql_query("REPLACE into list
(id, name, link, description, cost, date_added,type,myipaq,private,imgurl)
VALUES ('$id','$name','$link',"'$description'",'$cost','$date','$type','$myipaq','$private','$imgurl')");
Run Code Online (Sandbox Code Playgroud)
提前致谢,
格雷格
我正在读取文本文件并处理一些记录,文本文件的相关示例是
#export_dategenre_idapplication_idis_primary
#primaryKey:genre_idapplication_id
#dbTypes:BIGINTINTEGERINTEGERBOOLEAN
#exportMode:FULL
127667880285760063715151750
127667880285760123715151751
Run Code Online (Sandbox Code Playgroud)
我想在application_id已存储在我的数据库中并且is_primary = 1时执行特定操作
我写了这个PHP来测试我的代码:
$fp1 = fopen('genre_application','r');
if (!$fp) {echo 'ERROR: Unable to open file.'; exit;}
while (!feof($fp1)) {
$line = stream_get_line($fp1,128,$eoldelimiter); //use 2048 if very long lines
if ($line[0] === '#') continue; //Skip lines that start with #
$field = explode ($delimiter, $line);
list($export_date, $genre_id, $application_id, $is_primary ) = explode($delimiter, $line);
// does application_id exist?
$application_id = mysql_real_escape_string($application_id);
$query = "SELECT * FROM jos_mt_links WHERE link_id='$application_id';";
$res = mysql_query($query);
if (mysql_num_rows($res) > …Run Code Online (Sandbox Code Playgroud) 我需要通过PHP下载一个非常大的文件,上次我通过http手动完成它的大小为2.2gb并花了几个小时下载.我想以某种方式自动下载.
以前我用过
file_put_contents($filename, file_get_contents($url));
Run Code Online (Sandbox Code Playgroud)
这样的大文件会好吗?我想在下载后解压缩文件,然后对tarball中的各种文件进行分析.
我有一个800mb文本文件,其中包含18,990,870行(每行是一条记录),我需要选择某些记录,如果有匹配则将它们写入数据库.
它花了一个时间来完成它们,所以我想知道是否有办法更快地完成它?
我的PHP一次读取一行,如下所示:
$fp2 = fopen('download/pricing20100714/application_price','r');
if (!$fp2) {echo 'ERROR: Unable to open file.'; exit;}
while (!feof($fp2)) {
$line = stream_get_line($fp2,128,$eoldelimiter); //use 2048 if very long lines
if ($line[0] === '#') continue; //Skip lines that start with #
$field = explode ($delimiter, $line);
list($export_date, $application_id, $retail_price, $currency_code, $storefront_id ) = explode($delimiter, $line);
if ($currency_code == 'USD' and $storefront_id == '143441'){
// does application_id exist?
$application_id = mysql_real_escape_string($application_id);
$query = "SELECT * FROM jos_mt_links WHERE link_id='$application_id';";
$res = mysql_query($query);
if (mysql_num_rows($res) …Run Code Online (Sandbox Code Playgroud) 我有一个变量,它以英国格式保存日期,即250711,即2011年7月25日
当我将其插入MYSQL时,它变为2025-07-11
如何在写入MySQL之前将其转换为在MySQL中正确显示为2011-07-25?
非常感谢,
格雷格