在PHP printf中添加链接

在PHP printf中添加链接,php,html,wordpress,Php,Html,Wordpress,我在buddypress上设置了一个脚本,它在“成员区域”显示用户,如果他们有通知,它只打印“您有新通知(22)”或“您没有任何通知” 典型的设置,我对如何正确打印一个不会改变的链接有点迷茫 目前,他们收到通知时的代码为 if ( $instance['show_count_in_title'] ) { printf( "<span class='notification-count-in-title'>(%d)</span>", $count ); } if(

我在buddypress上设置了一个脚本,它在“成员区域”显示用户,如果他们有通知,它只打印“您有新通知(22)”或“您没有任何通知”

典型的设置,我对如何正确打印一个不会改变的链接有点迷茫

目前,他们收到通知时的代码为

if ( $instance['show_count_in_title'] ) {
    printf( "<span class='notification-count-in-title'>(%d)</span>", $count );
}
if($instance['show\u count\u in\u title'])){
printf((%d)”,$count);
}
然而,当我添加到文本的链接时,它会断开,我在范围内和范围外都尝试过,但总是在(“…我对PHP不太了解,所以可能我用这种方式使用链接是错误的?但我猜更多,所以我不明白为什么 当我这样做的时候

if ( $instance['show_count_in_title'] ) {
    printf( "<a href="me/notifications"><span class='notification-count-in-title'>(%d)</span></a>", $count );
}
if($instance['show\u count\u in\u title'])){
printf(“,$count);
}
我得到以下错误:

解析错误:语法错误,第59行的/homepages/2/D67646382/htdocs/dc/wp content/plugins/buddypress notifications widget/core/class-bp-notification-widget.php中出现意外的“http”(T_字符串)


我想我输入的PHP的a href不正确,但我很难弄清楚它应该是什么。

您需要避开反斜杠:

printf( "<a href=\"me/notifications\"><span class='notification-count-in-title'>(%d)</span></a>", $count );
printf(“,$count);
或者继续使用单斜杠:

printf( "<a href='me/notifications'><span class='notification-count-in-title'>(%d)</span></a>", $count );
printf(“,$count);
此外,我强烈建议使用单引号,内部使用双引号。(更多信息):

printf(“”,$count);

因为您没有在字符串中包含变量(您是通过printf传入的),所以没有理由让PHP尝试解析字符串以查找变量。

您需要避开反斜杠:

printf( "<a href=\"me/notifications\"><span class='notification-count-in-title'>(%d)</span></a>", $count );
printf(“,$count);
或者继续使用单斜杠:

printf( "<a href='me/notifications'><span class='notification-count-in-title'>(%d)</span></a>", $count );
printf(“,$count);
此外,我强烈建议使用单引号,内部使用双引号。(更多信息):

printf(“”,$count);

因为您没有在字符串中包含变量(您是通过printf传入的),所以没有理由让PHP尝试解析字符串以查找变量。

使用单引号或转义内部双引号:

printf( '<a href="me/notifications"><span class="notification-count-in-title">(%d)</span></a>', $count );
printf(“”,$count);
…或:

printf( "<a href=\"me/notifications\"><span class='notification-count-in-title'>(%d)</span></a>", $count );
printf(“,$count);

使用单引号或转义内部双引号:

printf( '<a href="me/notifications"><span class="notification-count-in-title">(%d)</span></a>', $count );
printf(“”,$count);
…或:

printf( "<a href=\"me/notifications\"><span class='notification-count-in-title'>(%d)</span></a>", $count );
printf(“,$count);

您需要退出

  printf( "<a href=\"me/notifications\"><span class=\"notification-count-in-title\">(%d)</span></a>", $count );

你要么逃跑

  printf( "<a href=\"me/notifications\"><span class=\"notification-count-in-title\">(%d)</span></a>", $count );

您可以安全地将href切换为使用单引号,如
'notification-count-in-title'
使用。您可以安全地将href切换为使用单引号,如
'notification-count-in-title'
使用。感谢这非常有效。了解不同的方法和首选方法也非常有帮助。感谢加载,真的吗as帮我澄清了这一点。谢谢,这非常有效。知道不同的方法和首选方法也非常有帮助。谢谢,真的帮我澄清了这一点。