php/html

编程入门 行业动态 更新时间:2024-10-17 12:18:25
本文介绍了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

本文发布于:2023-11-29 20:52:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:php   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!