dongyou6768 2018-05-18 04:55
浏览 215

php中的字符串内的单引号,双引号问题[复制]

I will print the string in PHP, but in a string in there middle of in string double quotes, single quotes string also .So I will not get the expected output.

My code Below:

<?php
$str = "Couldn't pay via card";
echo $str . " New "home" away from home when in Bangkok";
echo addslashes($str) . " This is safe in a database query.";
?> 

I will useaddslashes() function of PHP to display the string but there some error occurred

output :

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in on line no 5.

How it can be solved?

</div>
  • 写回答

1条回答 默认 最新

  • dongrunying7537 2018-05-18 04:59
    关注

    You can simly use slashes before your inner quotes like:

    echo $str . " New \"home\" away from home when in Bangkok";
    

    or change to single quotes

    echo $str . ' New "home" away from home when in Bangkok';
    

    Using single quotes mixed with double quotes does no harm, you can use code like:

    "This is " . 'some "sample" text! and it uses \'many\' quotes'
    
    评论

报告相同问题?

悬赏问题

  • ¥20 Keil编译时报错"no source": Error: #5: cannot open source
  • ¥50 操作系统时间无法更新
  • ¥20 Windows11, usb转hdmi,外接显示器无反应
  • ¥20 怎么在JavaFx的TableView中动态地添加数据。
  • ¥15 MFC里的工具栏按钮图标使用外部图片
  • ¥15 如何在 llama.cpp 服务器中实现用户登录功能的优化方案?(语言-c++)
  • ¥15 有会用octave 的吗,急!代做!好偿!
  • ¥15 有一套同城小程序源码,Uniapp前端,php+html+mysql后端 ,能不能教我搭建起来可以运行,我不知道怎样操作
  • ¥15 mac调用java.io接口无法在根目录生成文件
  • ¥15 java微服务节点假死,网关路由时长延迟