在PHP printf中添加链接

时间:2018-08-01 18:07:25

标签: php html wordpress

我在buddypress上设置了一个脚本,该脚本在“成员区域”上向用户显示是否有通知,它只显示“您有新通知(22)”或“您没有任何通知”。

典型设置,我对如何正确打印不会改变的链接有些困惑。

当前他们收到通知的代码是

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.amazonaws.unity"
      android:installLocation="preferExternal"
    android:versionCode="1"
    android:versionName="1.0">

  <supports-screens
      android:smallScreens="true"
      android:normalScreens="true"
      android:largeScreens="true"
      android:xlargeScreens="true"
      android:anyDensity="true"/>

  <uses-sdk android:minSdkVersion="9" />


  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

  <permission android:name="com.amazonaws.unity.permission.C2D_MESSAGE"
      android:protectionLevel="signature" />
  <uses-permission android:name="com.amazonaws.unity.permission.C2D_MESSAGE" />


  <application
      android:theme="@android:style/Theme.NoTitleBar"
      android:icon="@drawable/app_icon"
      android:label="@string/app_name"
      android:debuggable="true">

    <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
              android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>

    <receiver
        android:name="com.amazonaws.unity.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
        <category android:name="com.amazonaws.unity" />
      </intent-filter>
    </receiver>

    <service android:name="com.amazonaws.unity.GCMIntentService" />
  </application>
</manifest>

但是,当我在文本中添加链接时,它会中断,我在跨度和外部都尝试过,但是总是在(“ ..我不完全了解PHP,所以也许我使用链接是错误的这样呢?但是我想更多,所以我很困惑为什么

当我这样做时;

if ( $instance['show_count_in_title'] ) {
    printf( "<span class='notification-count-in-title'>(%d)</span>", $count );
}

我收到以下错误:

  

解析错误:语法错误,/ homepages / 2 / d676463482 / htdocs / dc / wp-content / plugins / buddypress-notifications-widget / core / class-bp-notification-widget中出现意外的'http'(T_STRING)。第59行的php

我想我为PHP输入的href错误,但是我很难弄清楚它应该是什么。

3 个答案:

答案 0 :(得分:1)

您需要转义反斜杠:

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 );

此外,我强烈建议使用单引号,并在内部使用双引号。 (有关此here的更多信息):

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

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

答案 1 :(得分:1)

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

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 );

答案 2 :(得分:1)

您需要逃脱

  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 );
相关问题