引号在页面上导致错误 [英] Quotation Marks Causing Error on Page

查看:108
本文介绍了引号在页面上导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的希望有人能帮助我。我一直在用这个头撞墙:(。



我有下面的代码让我疯狂



在我的PHP文件中,我输入了以下代码来显示一系列AZ链接:

 < div> 
< ul id =AZList>
< li>< a id =LetterLink1href =javascript:showonlyone('LetterList1');>#< / a>< / li>
<?php



$ lettercounter = 1;
for($ i = 65; $ i< ; = 90; $ i ++){

$ lettercounter = $ lettercounter + 1;
$ LetterLinkLbL =ListLetter。$ lettercounter;
?>

< li>< a id =LetterLink<?php echo $ lettercounter?>href =javascript:showonlyone('<?php echo $ LetterLinkLbL?>');>< ?php echo chr($ i)?>< / a>< / li>



<?php}?>
< ; / ul>

< / div>

酸ce文件显示为

 < li>< a id =LetterLink1href =javascript:showonlyone(LetterList1 );>#< / A>< /锂> 

< li>< a id =LetterLink2href =javascript:showonlyone(ListLetter2);> A< / a>< / li>
$ b< / a>< / b&李>

在页面上导致错误



<第一个应该是:

 < li>< a id =LetterLink1href =javascript:showonlyone ( 'LetterList1');>#< / A>< /锂> 

有谁知道我怎样才能让引号正确显示?






我刚从我的笔记本电脑上传文件到远程服务器,它的工作方式应该不会改变文件。



我通过向页面写入echo语句来确认我正在处理和查看同一个文件。



为什么它会在我的本地主机上显示这样的内容?

谢谢您的所有评论

解决方案

您的代码和输出应该给您带来的差异:您的代码:



b
$ b

  href =javascript:showonlyone('<?php echo $ LetterLinkLbL?>'); 

必定会呈现:

  HREF = JavaScript的:showonlyone( 'ListLetter3'); 

但是您声明它呈现(在开始时使用双引号,在末尾使用单引号):

  href =javascript:showonlyone(ListLetter3');

你给的php代码不应该创建错误,因为它是正确的。
你确定你没有给我们输出另一个试验?



在PHP / javascript字符串中使用相同的引号括起来的规则只是在它之前添加一个\:

  $ Value =Hello Johnny \PHP \Boy !!; 

  $ Value ='Hello Johnny \\ \\'PHP \\''boy!'; 


I really hope someone can help me. I've been banging my head against the wall with this one :(.

I have the following code that is driving me nuts

In my PHP file I have entered the following code to display a series of A-Z Links:

<div>
 <ul id="AZList">
     <li><a id="LetterLink1" href="javascript:showonlyone('LetterList1');">#</a></li>
  <?php 



   $lettercounter=1;
   for ($i=65; $i<=90; $i++){

      $lettercounter=$lettercounter+1;
      $LetterLinkLbL="ListLetter".$lettercounter;
?>

          <li><a id="LetterLink<?php echo $lettercounter ?>" href="javascript:showonlyone('<?php echo $LetterLinkLbL ?>');"><?php echo chr($i) ?></a></li>         



  <?php } ?>
    </ul>

</div>

But when I view the source file it displays as

  <li><a id="LetterLink1"  href="javascript:showonlyone("LetterList1');">#</a></li>

      <li><a id="LetterLink2"  href="javascript:showonlyone("ListLetter2');">A</a></li>         




      <li><a id="LetterLink3"  href="javascript:showonlyone("ListLetter3');">B</a></li>

Which is causing an error on the page

The first one should read:

 <li><a id="LetterLink1"  href="javascript:showonlyone('LetterList1');">#</a></li>

Does anyone know how I can get the quotes to display correctly?


I've just uploaded the file from my laptop to the Remote server and it is working as it should without me making any changes to the file.

I did confirm that I was working on and viewing the same file, by writing an echo statement to the page.

Why would it be showing like this on my localhost? Does anyone have an idea what he issue could be?

Thank you for all your comments by the way

解决方案

There is discrepancy between what you have in your code and the ouput should give you :

Your code :

href="javascript:showonlyone('<?php echo $LetterLinkLbL ?>');"

is bound to render :

href="javascript:showonlyone('ListLetter3');"

but you state it renders (with a double quotation mark at the start and a single one at the end) :

href="javascript:showonlyone("ListLetter3');"

The php code you give should not create an error at all as it is correct. Are you sure you did not give us the output from another trial ?

The rule to insert a quotation inside a PHP/javascript string using that same quotation to enclose it is simply to add a \ before it :

$Value = "Hello Johnny \"PHP\" Boy !!";

or

$Value = 'Hello Johnny \'PHP\' boy !';

这篇关于引号在页面上导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆