zoukankan      html  css  js  c++  java
  • php 单引号 双引号 区别

    今天,有一新学PHP的网友问了茶农一个问题:“单引号和双引号的区别和用法?”,现将答案总结了下,写成这篇小短文。 

    " "双引号里面的字段会经过编译器解释,然后再当作HTML代码输出。 

    ' '单引号里面的不进行解释,直接输出。 

    例如: 
    $abc='my name is tome'; 
    echo $abc //结果是:my name is tom 
    echo '$abc' //结果是:$abc 
    echo "$abc" //结果是:my name is tom 

    特别在使用MYSQL语句的时候,双引号和单引号的用法让新手不知所措,在这里,举个例子,来进行说明。 

    假设查询条件中使用的是常量,例如: 

    select    *    from    abc_table where user_name='abc'; 

    SQL语句可以写成: 

    SQLstr = "select    *    from abc_table where user _name= 'abc'" ; 

    假设查询条件中使用的是变量,例如: 

    $user_name = $_REQUEST['user_name']; //字符串变量 

    或 

    $user=array ("name"=> $_REQUEST['user_name‘,"age"=>$_REQUEST['age'];//数组变量 

    SQL语句就可以写成: 

    SQLstr = "select    *    from abc_table where user_name = ' " . $user_name . " ' "; 

    SQLstr = "select * from abc_table where user_name = ' " . $user["name"] . " ' "; 

    对比一下: 

    SQLstr="select * from abc_table where user_name = ' abc ' " ; 

    SQLstr="select * from abc_table where user_name =' " . $user _name . " ' "; 

    SQLstr="select * from abc_table where user_name =' " . $user["name"] . " ' "; 

    SQLstr可以分解为以下3个部分: 
    1:"select * from table where user_name = ' " //固定SQL语句 
    2:$user //变量 
    3:" ' " 
    1,2,3部分字符串之间用"." 来连接 

  • 相关阅读:
    Windows删除git本地记住的密码
    C++ fmt库的安装和测试
    仿照struct is_integral 实现struct not_int
    folly库net库udp小例子
    Java阻塞队列BlockingQueue
    正则表达式必知必会摘要
    正则表达式匹配IP地址
    SimpleDateFormat线程安全性测试与解决方案
    Java8 HashMap中哈希桶(table)数组的索引位置
    socket网络编程--基础应用篇
  • 原文地址:https://www.cnblogs.com/zcy_soft/p/1933007.html
Copyright © 2011-2022 走看看