PHP 中的混合引号 [英] Mixing quotes in PHP

查看:34
本文介绍了PHP 中的混合引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个脚本可以从数据库中获取我的信息

I have this script that gets my info from the DB

$result = mysqli_query($con,"SELECT * FROM <table> WHERE id = 3");

while($row = mysqli_fetch_array($result))
  {
  echo '<p>'.$row['name'].'</p>' . " " .'<p>' . $row['description'] . '</p>' . " " . '<p>' . $row['price'] . '</p>';
  echo "<br>";
  echo '<img src="http://www.example.com/images/'.$row['profile_pic'].'" alt="profilepic" />';
  echo '<img src="http://www.example.com/images/'.$row['pic1'].'" alt="pic1" />';
      ^^^                                                *********
      Here is the problem because I should have sigle quote at the beginning and at the end, but I still have it above ***.And I use double quotes for the src on the <img> so those are taken too.
  echo '<img src="http://www.example.com/images/'.$row['pic2'].'" alt="pic2" />';
  echo '<img src="http://www.example.com/images/'.$row['pic3'].'" alt="pic3" />';
  }

如果我按照我的意图去做,我将需要另一套引用器(可能是三重 :]] )..我怎样才能以正确的方式做到这一点?

If I do it like I intended, I would need another set of quoter( maybe triple :]] )..How can I do it the right way?

推荐答案

您拥有的源代码看起来不错.您可以在单引号或双引号之前使用 \ 字符来转义,如下所示:

The source code you have looks good. You can use \ character immediately ahead of a single or double quote to escape, like so:

$variable = "我的报价是\"像这样\" ";

//输出:我的报价是像这样"

同样:

$variable = '这就是我的报价"的样子';

//输出:这是我的引号"的样子

这篇关于PHP 中的混合引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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