我正在尝试一个简单的测试,只有当$checkpoint_date不到7天时,javascript才需要运行。
<?php
$checkpoint_date = '15-08-2013';
if (strtotime($checkpoint_date) < strtotime('-7 day')){
?>
<script> alert('hi'); </script>
<?php } ?>无论计算结果是否为true,alert似乎都在运行。
我知道上述条件是可行的,因为我已经测试过它:
if (strtotime($checkpoint_date) < strtotime('-7 day')){
echo 'more than 7 days';
}else{
echo 'less than 7 days';
}发布于 2013-08-15 03:20:02
我已经测试过这个代码了。它应该能正常工作。
$today = date("d-m-Y");
$checkpoint_date = '15-08-2013';
if (strtotime($checkpoint_date) - strtotime($today) > 7){
echo "<script>alert('More than 7 days')</script>";
}else{
echo "<script>alert('Less than 7 days')</script>";
}第二项答覆:
我试着测试你的代码。实际上很好用。但我使用echo输出javascript。
$checkpoint_date = '15-08-2013';
if (strtotime($checkpoint_date) < strtotime('-7 day')){
echo "<script>alert('less than');</script>";
}else{
echo "<script>alert('more than');</script>";
}发布于 2013-08-15 03:09:48
还没有测试过,但这应该可以做到:
<?php
//last time
$checkpoint_date = '15-08-2013';
if ( strtotime($checkpoint_date) < strtotime('-7 day') ) {
$script = '<script> alert("hi"); </script>';
}
else {
$script = '';
}
echo $script;
?>发布于 2013-09-07 08:28:37
// Get the contents of the pdf into a variable for later
ob_start();
require_once('pdf.php');
$pdf_html = ob_get_contents();
ob_end_clean();
require_once($dir.'/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF(); // Create new instance of dompdf
$dompdf->load_html($pdf_html); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->output(); // Put contents of pdf into variable for laterhttps://stackoverflow.com/questions/18245693
复制相似问题