使用javascript显示php时间/日期函数的帮助
我想删除谷歌搜索显示的元日期。我在single.php中发现了这段代码使用javascript显示php时间/日期函数的帮助,php,javascript,Php,Javascript,我想删除谷歌搜索显示的元日期。我在single.php中发现了这段代码 <?php the_time(‘M j, Y’);?> 需要重新编写为: <script language=”javascript” type=”text/javascript”> document.write(‘<?php the_time(‘j’) ?>’); </script> <?php the_time(‘M Y’) ?> document.wri
<?php the_time(‘M j, Y’);?>
需要重新编写为:
<script language=”javascript” type=”text/javascript”> document.write(‘<?php the_time(‘j’) ?>’); </script> <?php the_time(‘M Y’) ?>
document.write(“”);
然而,我的single.php使用这种格式
<?php the_time(get_option('date_format')); ?>
如何将javascript用于上述代码?document.write(“”);
<script language=”javascript” type=”text/javascript”> document.write(‘<?php the_time(get_option("date_format")); ?>’);</script>
这将隐藏整个日期,而不仅仅是一个月的某一天。(这就是你想要的吗?尽管一行程序可以工作,但这样编写的代码会导致代码混乱。 你的代码应该像一本书一样易于阅读和理解
<?php
// the date() object should be used for this, and the following would normally by
// shoved in a function.
$date['j'] = the_time('j',get_option('date_format'));
$date['M'] = the_time('M', get_option('date_format'));
$date['Y'] = the_time('Y', get_option('date_format'));
// Build the date string the way want it
$date['full'] = "Today, the " . $date['j'] . "of " . $date['M'] . ", " . $date['Y'];
?>
<script language="javascript" type="text/javascript">document.write('<?php echo date["full"]; ?>');</script>
文件。写(“”);
时间?从未见过这个,这是你自己的函数还是你的框架?这是它给出的错误:解析错误:语法错误,意外“;”@特罗特:你忘了回显时间函数…)那么它将是这种格式?document.write('@Vaibhav:我没有平衡括号。我只是编辑了它来修复它。现在就试试。@Vaibhav:不需要echo
,事实上这可能不起作用。从OP在问题中发布的代码中可以清楚地看出the_time()
本身进行回显。它可能返回true或false,因此添加一个回显
可能不会得到OP想要的结果。