PHP帮忙?解析错误:语法错误,第6行意外T_STRING

时间:2015-02-09 21:03:08

标签: php wordpress

任何人都知道我在这里做错了什么?我在Wordpress儿童主题的functions.php文件中有这段代码。

<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
' . __( "This content is CLASSIFIED, for subscribers only! To get access, <a href="http://maryefern.com/join">join here</a>, check your e-mail for a message from me with the password, and enter it below:" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
?>

1 个答案:

答案 0 :(得分:0)

该错误通常意味着您有一些不应该的文本(字符串)。当我收到此错误时,这意味着我可能没有正确地转义某些内容,或者没有正确地“跳入”/跳出php。

为了帮助减少这种情况,我将把标记/输出分成不同的行。当然它会使代码更长(更多行),但它只是有助于保持正确。

我不知道这段代码是否有效,但至少你的错误消失了。 @ceejayoz是对的,语法高亮应该可以帮到你。

<强> PHP

    function my_password_form() {
        global $post;
        $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );

        $o = '<form action="' . esc_url(site_url('wp-login.php?action=postpass', 'login_post')) . '" method="post">';
        $o .= '(This content is CLASSIFIED, for subscribers only! To get access, <a href="http://maryefern.com/join">join here</a>, check your e-mail for a message from me with the password, and enter it below:)';
        $o .= '<label for="' . $label . '">' . ( "Password:" ) . '</label>';
        $o .= '<input name = "post_password" id = "' . $label . '" type = "password" size = "20" maxlength = "20" /><input type = "submit" name = "Submit" value = "' . esc_attr__( "Submit" ) . '" />';
        $o .= '</form>';

        return $o;
}

add_filter('the_password_form', 'my_password_form');