PHP回显多个HTML链接

时间:2012-01-31 15:35:21

标签: php html

嘿伙计们如何使这些php html链接代码成为可能。我尝试了很多方法,但链接显示不正确。

echo "<a href="http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/1%20CLIST%20AEE2011.pdf" 
onclick="window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/3%20AGO%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/4%20CAB%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/6%20PARL%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/7%20PRESCO%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/21%20PMO%20AEE2011.pdf');"
>Government Administration Expenditure Details</a>";

5 个答案:

答案 0 :(得分:1)

  1. 使用"
  2. 替换\",使用正确的引号
  3. 使用分号(在onclickwindow.open(...)之间分隔window.open(...)处理程序中的表达式。
  4. 代码:

    echo "<a href=\"http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/1%20CLIST%20AEE2011.pdf\" 
    onclick=\"window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/3%20AGO%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/4%20CAB%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/6%20PARL%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/7%20PRESCO%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/21%20PMO%20AEE2011.pdf');\"
    >Government Administration Expenditure Details</a>";
    

    另一种方法是:

    echo <<<LABEL
    <a href="http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/1%20CLIST%20AEE2011.pdf" 
    onclick="window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/3%20AGO%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/4%20CAB%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/6%20PARL%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/7%20PRESCO%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/21%20PMO%20AEE2011.pdf');"
    >Government Administration Expenditure Details</a>
    LABEL;
    

答案 1 :(得分:1)

您在echo语句中使用双引号,但也在内容中使用双引号而不转义它们。所以你在声明中使用的每个双引号都应该使用反斜杠进行转义:

echo "He said "hi there" to me";

变为:

echo "He said \"hi there\" to me";

答案 2 :(得分:1)

将您的代码更改为:

echo '<a href="http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/1%20CLIST%20AEE2011.pdf" 
onclick="window.open(\'http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/3%20AGO%20AEE2011.pdf\')
window.open(\'http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/4%20CAB%20AEE2011.pdf\')
window.open(\'http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/6%20PARL%20AEE2011.pdf\')
window.open(\'http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/7%20PRESCO%20AEE2011.pdf\')
window.open(\'http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/21%20PMO%20AEE2011.pdf\');"
>Government Administration Expenditure Details</a>';

您需要使用反斜杠转义引号。

使用希罗多克:

echo <<<EOF
<a href="http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/1%20CLIST%20AEE2011.pdf" 
onclick="window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/3%20AGO%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/4%20CAB%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/6%20PARL%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/7%20PRESCO%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/21%20PMO%20AEE2011.pdf');">
Government Administration Expenditure Details</a>
EOF;

希望这可以帮助你:)

答案 3 :(得分:1)

就个人而言,我会将你的onclick事件中的所有内容都分解为一个javascript函数。

openLinks(){
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/3%20AGO%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/4%20CAB%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/6%20PARL%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/7%20PRESCO%20AEE2011.pdf');
    window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/21%20PMO%20AEE2011.pdf');
}

然后在你的onclick()中调用该函数。使更清洁的HTML IMO

<a href="link_here" onclick="openLinks();">text</a>

答案 4 :(得分:0)

您可以像这样使用HEREDOC:

echo <<< EOF
<a href="http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/1%20CLIST%20AEE2011.pdf" 
onclick="window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/3%20AGO%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/4%20CAB%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/6%20PARL%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/7%20PRESCO%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/21%20PMO%20AEE2011.pdf')
>Government Administration Expenditure Details</a>
EOF;

否则甚至不使用echo就像这样关闭php标签(如果你没有在echo中使用任何php变量):

// end the php code
?>
<a href="http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/1%20CLIST%20AEE2011.pdf" 
onclick="window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/3%20AGO%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/4%20CAB%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/6%20PARL%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/7%20PRESCO%20AEE2011.pdf')
window.open('http://www.mof.gov.sg/budget_2011/revenue_expenditure/attachment/21%20PMO%20AEE2011.pdf')
>Government Administration Expenditure Details</a>
<?php // start php code