带有变量和函数的PHP echo
我正在尝试创建一个自动刷新url,如下所示,但它似乎不起作用带有变量和函数的PHP echo,php,variables,url,echo,page-refresh,Php,Variables,Url,Echo,Page Refresh,我正在尝试创建一个自动刷新url,如下所示,但它似乎不起作用 <?php $lastid = 12345 redirect = echo the_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid'; echo '<meta http-equiv="refresh" content="1; url='$redirect'">'; ?> 您不能首先使用echo语句设置任何变量值。您需要在可以ec
<?php
$lastid = 12345
redirect = echo the_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid';
echo '<meta http-equiv="refresh" content="1; url='$redirect'">';
?>
您不能首先使用echo语句设置任何变量值。您需要在可以echo$redirect之后设置变量$redirect值
您正在使用WordPress,对吗?我可以通过permalink
和get\u选项
函数进行猜测。如果是这样,下面的代码应该适合您
更多说明:[编辑]
请参阅Nirav Joshi的PHP错误。另外,当您使用WordPress时
永久链接实际上与url相呼应。您应该使用get\u permalink
将url存储在$redirect
变量中
使用此代码:
$lastid = 12345;
$redirect = get_permalink(get_option( 'cts_return_page' )) . '?transid=' . $lastid;
echo '<meta http-equiv="refresh" content="1; url=' . $redirect . '">';
$lastid=12345;
$redirect=get_permalink(get_选项('cts_return_page'))?transid='$拉斯蒂德;
回声';
您在代码中犯了一些错误,如
- 您不应该像
$redirect=echo
那样使用echo
- 您必须使用
$redirect
而不是redirect
- 无需在
$lastid
之后使用'
- 并使用
代码>在12345
之后
- 编辑与
连接。
类似url='.$redirect.
希望这对你有帮助
<?php
$lastid = 12345;
$redirect = the_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid;
echo '<meta http-equiv="refresh" content="1; url='.$redirect.'">';
?>
解决方案:
您遇到了什么问题??您正在使用WordPress,对吗?您没有提到OP将在哪里更改或问题是什么。谢谢。你评论的时候我正在编辑答案。谢谢@SougataBose。还更正了变量名和函数名。您没有提到OP将更改的位置或问题所在。@RïshïKïshKümar语法错误已解决。。lol:D我没有运行代码,我只是直接编辑了这个,这就是我犯错误的原因。。现在我只需检查localhost中的代码,它现在工作正常。。Thanx建议:)它在localhost
中不起作用。。。或者是在线提琴。。在_permalink
和
获取选项函数中获取错误@RïshïKïshKümar你在wordpress上查过了吗?没有。。实际上,它不是在我的本地计算机中设置的。。所以我只是在本地服务器上进行了尝试,并得到了错误信息。现在正在等待Jeremy的回复
<?php
$lastid = 12345;
$redirect = the_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid;
echo '<meta http-equiv="refresh" content="1; url='.$redirect.'">';
?>
<?php
$lastid = 12345;
$redirect = the_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid;
echo " <meta http-equiv='refresh' content='1'; url ='<?php $redirect ?>' > ";
?>
<?php
//$redirect = get_permalink(get_option( 'cts_return_page' )).'?transid='.$lastid;
//$url = "http://example.com/page-from-options?transid=12345";
$lastid = 12345;
// Retrieve the `cts_return_page`, and storing it in a variable.
echo $get_options = get_option('cts_return_page');
//Displays the URL to the post:
echo $redirect = the_permalink($get_options).'?transid='.$lastid;
//echo " <meta http-equiv='refresh' content='1'; url ='http://example.com/<?php $redirect ?>' > ";
?>
<meta http-equiv='refresh' content='1' url='http://example.com/<?php echo $redirect; ?>' >