php/html-三重嵌套引号 [英] php/html - triple nesting quotes

查看:595
本文介绍了php/html-三重嵌套引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Stack Overflow上已经问过很多类似的问题,但是我在html/php中存在三重嵌套引号的问题.我已经看过许多问题,但是没有找到适合我的解决方案.这是我想要做的(在php文件中找到):

I know that similar questions have been asked on Stack Overflow many times, but I am having problems with triple nested quotes in html/php. I have looked at numerous questions, but none of the solutions that I have found are working for me. Here is what I am trying to do (this is found in a php file):

                    echo"<div id = 'feed-element'>
                    <button class='username-button' type='button'>@".$currentUsername."</button>
                    <button class='hashtag-one-button' type='button'>".$hashtag_one."</button>
                    <button class='hashtag-two-button' type='button'>".$hashtag_two."</button>
                    <button class='play-button' id='play-button".$i."' type='button' onclick='changeImage(this.id,\'".$track_url."\')'></button>
                    <button class='email-button' type='button'>Contact: ".$email."</button>
                </div>";

导致我出现问题的特定行是倒数第三行:

The specific line that is causing me problems is the third to last line:

<button class='play-button' id='play-button".$i."' type='button' onclick='changeImage(this.id,\'".$track_url."\')'></button>

无论如何,当我运行这段代码时,我得到了一个Uncaught语法:无效或意外的令牌错误.我在做什么错了?

Anyways, when I run this code I get an Uncaught Syntax: invalid or unexpected token error. What am I doing wrong?

推荐答案

对于引起错误的代码,您需要转义双引号,而不是单引号:

For your error-causing code, you need to escape double quotes, not single:

<button class='play-button' id='play-button".$i."' type='button' onclick='changeImage(this.id,\"".$track_url."\")'></button>

因为使用双引号,所以不需要串联.只需插入变量就可以了!

Because you are using double quotes, you don't need to concatenate. Just insert the variable and away you go!

echo"<div id='feed-element'>
      <button class='username-button' type='button'>@$currentUsername</button>
      <button class='hashtag-one-button' type='button'>$hashtag_one</button>
      <button class='hashtag-two-button' type='button'>$hashtag_two</button>
      <button class='play-button' id='play-button$i' type='button' onclick='changeImage(this.id,\' $track_url\ ')'></button>
      <button class='email-button' type='button'>Contact: $email</button>
  </div>";

这篇关于php/html-三重嵌套引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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