Hướng dẫn does php use single or double quotes? - php sử dụng dấu nháy đơn hay kép?

Cải thiện bài viết

Show

Lưu bài viết

  • Đọc
  • Bàn luận
  • Cải thiện bài viết

    Lưu bài viết

    ĐọcSingle-quoted Strings: It is the easiest way to define a string. You can use it when you want the string to be exactly as it is written. All the escape sequences like \r or \n, will be output as specified instead of having any special meaning. Single-quote is usually faster in some cases. The special case is that if you to display a literal single-quote, escape it with a backslash (\) and if you want to display a backslash, you can escape it with another backslash (\\)

    Bàn luậnSingle-quoted Strings: 

    Trích dẫn đơn hoặc kép trong lập trình PHP được sử dụng để xác định một chuỗi. Nhưng, có rất nhiều sự khác biệt giữa hai người này. Chuỗi được trích xuất đơn: Đó là cách dễ nhất để xác định một chuỗi. Bạn có thể sử dụng nó khi bạn muốn chuỗi được chính xác như nó được viết. Tất cả các chuỗi thoát như \ r hoặc \ n, sẽ được đầu ra theo quy định thay vì có bất kỳ ý nghĩa đặc biệt nào. Quan điểm đơn thường nhanh hơn trong một số trường hợp. Trường hợp đặc biệt là nếu bạn hiển thị một trình điều khiển đơn theo nghĩa đen, hãy thoát nó bằng dấu gạch chéo ngược (\) và nếu bạn muốn hiển thị dấu gạch chéo ngược, bạn có thể thoát nó bằng một dấu gạch chéo ngược khác (\\). & NBSP; 

    Dưới đây chương trình minh họa các chuỗi được trích xuất đơn: & NBSP;

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    7

    Chương trình 1: & NBSP;

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    PHP

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    9
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    5
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    1
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    6
    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    7
    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    1
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    Output:

    I am a geek. 
    It'll be interesting to know about the string. 
    A \ is named as backslash. 
    This is a portal for $string. 
    This is a portal for \n geeks.

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    7
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0
    By using Double quotes the PHP code is forced to evaluate the whole string. The main difference between double quotes and single quotes is that by using double quotes, you can include variables directly within the string. It interprets the Escape sequences. Each variable will be replaced by its value. 

    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    9Double-quoted Strings: 

    Các chuỗi được trích dẫn kép: Bằng cách sử dụng trích dẫn kép, mã PHP buộc phải đánh giá toàn bộ chuỗi. Sự khác biệt chính giữa báo giá kép và trích dẫn đơn là bằng cách sử dụng dấu ngoặc kép, bạn có thể bao gồm các biến trực tiếp trong chuỗi. Nó diễn giải các chuỗi thoát. Mỗi biến sẽ được thay thế bằng giá trị của nó. & NBSP; 

    Dưới đây chương trình minh họa các chuỗi được trích xuất đơn: & NBSP;

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    7

    Chương trình 1: & NBSP;

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    PHP

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    9
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    5
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    1
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    9

    Output:

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.

    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    6
    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    7
    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    1
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0
    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    7
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    9
    1. Các chuỗi được trích dẫn kép: Bằng cách sử dụng trích dẫn kép, mã PHP buộc phải đánh giá toàn bộ chuỗi. Sự khác biệt chính giữa báo giá kép và trích dẫn đơn là bằng cách sử dụng dấu ngoặc kép, bạn có thể bao gồm các biến trực tiếp trong chuỗi. Nó diễn giải các chuỗi thoát. Mỗi biến sẽ được thay thế bằng giá trị của nó. & NBSP;Dưới đây chương trình minh họa các chuỗi được trích dẫn kép: & nbsp;
    2.

    Chương trình 2: & NBSP;

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    print '
      '; print '
    • Flour - 300 grams
    • '
      ; print '
    • Butter - 200 grams
    • '
      ; print '
    • Water - 100 ml
    • '
      ; print '
    '
    ;
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    Chương trình 2: & NBSP;

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    print '
      '; print '
    • Flour - 300 grams
    • '
      ; print '
    • Butter - 200 grams
    • '
      ; print '
    • Water - 100 ml
    • '
      ; print '
    '
    ;
    2
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0

    3.
    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    print '
      '; print '
    • Flour - 300 grams
    • '
      ; print '
    • Butter - 200 grams
    • '
      ; print '
    • Water - 100 ml
    • '
      ; print '
    '
    ;
    8
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0
    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    4
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0
    4.
    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    6
    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;
    7
    echo 'Za\'atar is a Middle Eastern spice mix.';
    
    1
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0
    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    8
    echo 'Za\'atar is a Middle Eastern spice mix.';
    
    4
    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>
    0
    5.

    Hãy cho chúng tôi hiểu sự khác biệt trong một dạng bảng -:

    & nbsp;

    Hãy cho chúng tôi hiểu sự khác biệt trong một dạng bảng -:

    & nbsp;


    Tôi nên sử dụng trích dẫn đơn hay đôi?

    Trong tiếng Anh Hoa Kỳ, bạn phải sử dụng dấu ngoặc kép. Dấu một trích dẫn duy nhất được sử dụng cho báo giá trong báo giá. Trong tiếng Anh của Vương quốc Anh, việc sử dụng các dấu ngoặc đơn duy nhất phổ biến nhất, với dấu ngoặc kép cho các trích dẫn trong báo giá, mặc dù cách khác cũng được chấp nhận. Trích dẫn là gì?

    Các chuỗi được sử dụng như thế nào trong PHP?

    Theo các hàm chuỗi trong PHP, trong các ngôn ngữ lập trình, các hàm chuỗi được sử dụng để sửa đổi một chuỗi hoặc kiến ​​thức truy vấn về một chuỗi (một số làm cả hai) .... hàm độ dài (chuỗi) là ví dụ cơ bản nhất về hàm chuỗi. Độ dài của một chuỗi theo nghĩa đen được trả về bởi hàm này.

    Đây là một bài viết tôi đã viết một thời gian trước trên blog cũ của tôi khi tôi mới bắt đầu học PHP. Tôi sẽ đăng lại nó ở đây, trong trường hợp nó giúp bất cứ ai :)

    // Using single quotes to save a string in a variable:
    $recipe_title = 'Meatball Spaghetti';
    
    // Using single quotes to write something on the screen:
    echo '

    Meatball Spaghetti

    '
    ; // The line above will get output as-is in your code: <h2>Meatball Spaghettih2>

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Nếu bạn muốn lưu văn bản dưới dạng biến hoặc hiển thị nó trên màn hình (với nói, I am a geek. It'll be interesting to know about the string. This is a simple string. The word is ABC.8 hoặc echo 'Za\'atar is a Middle Eastern spice mix.'; 8), bạn phải bao quanh văn bản trong các trích dẫn. Văn bản xung quanh bằng trích dẫn làm cho văn bản đó trở thành một chuỗi.

    Bạn có thể sử dụng các trích dẫn đơn (

    echo 'Za\'atar is a Middle Eastern spice mix.';
    
    9) hoặc trích dẫn kép (____ 80), nhưng có một số khác biệt quan trọng, mà tôi sẽ xem trong bài đăng này.

    print '
    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml
    '
    ;

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Dấu nháy đơn

    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Trích dẫn đơn là cách đơn giản nhất để tạo một chuỗi. Họ chỉ hiển thị những gì chúng được đưa ra, không có chuông và còi, không có "quyền hạn" đặc biệt như có thể hiển thị các giá trị biến (xem bên dưới trong phần trích dẫn kép).

    print '
      '; print '
    • Flour - 300 grams
    • '
      ; print '
    • Butter - 200 grams
    • '
      ; print '
    • Water - 100 ml
    • '
      ; print '
    '
    ;

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Dấu nháy đơn

    • Flour - 300 grams
    • Butter - 200 grams
    • Water - 100 ml

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Trích dẫn đơn là cách đơn giản nhất để tạo một chuỗi. Họ chỉ hiển thị những gì chúng được đưa ra, không có chuông và còi, không có "quyền hạn" đặc biệt như có thể hiển thị các giá trị biến (xem bên dưới trong phần trích dẫn kép).

    Phá vỡ dòng với các trích dẫn đơn lẻ

    Nếu bạn cần hiển thị văn bản trên nhiều dòng, bạn có thể sử dụng ngắt dòng trong các trích dẫn để đạt được điều này. Ví dụ:

    Điều này sẽ được đầu ra như:

    echo 'Za\'atar is a Middle Eastern spice mix.';
    

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Điều này sẽ xuất hiện đúng như sau mà không gây ra lỗi.

    echo 'A \\ is called a "backslash."';
    
    5

    Hai: ________ 86 & nbsp; để thoát khỏi sự chao đảo, nhân vật thoát khỏi chuỗi

    Bạn đã có thể sử dụng

    echo 'A \\ is called a "backslash."';
    

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Để in

    echo 'A \\ is called a "backslash."';
    
    7

    *Nó có thể phụ thuộc vào trình biên dịch, nhưng khi tôi đang thử nghiệm điều này, & nbsp; & nbsp; ________ 88 & nbsp; dường như cũng tự mình hoạt động. Nhưng, nếu vì một lý do nào đó bạn muốn hiển thị & nbsp; ________ 86, bạn có thể cần sử dụng một cái gì đó như ________ 90 & nbsp; hoặc & nbsp; ________ 91. Vì nó là một nhân vật đặc biệt, có lẽ tốt nhất là thoát khỏi trường hợp.

    Dấu ngoặc kép

    Một sự khác biệt lớn về dấu ngoặc kép so với trích dẫn đơn là bạn có thể sử dụng dấu ngoặc kép để bao gồm các biến trực tiếp bên trong chuỗi. Nếu bạn sử dụng các trích dẫn đơn, bạn sẽ phải kết hợp các mảnh lại với nhau. Hãy xem một ví dụ.

    Giả sử bạn có công thức nấu ăn và bạn lưu các tiêu đề vào một biến gọi là

    $recipe_title = 'Meatball Spaghetti';
    
    2:

    $recipe_title = 'Meatball Spaghetti';
    

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Nếu bạn muốn tạo HTML cho các tiêu đề công thức để chúng trông như thế này (và bạn không nhúng PHP trực tiếp vào các tệp HTML, trong đó bạn có thể sử dụng thẻ ____93 thay vào đó để tạo ra các biến):

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    0

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Sử dụng các trích dẫn duy nhất bạn cần để thêm các phần khác nhau với nhau:

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    1

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Tuy nhiên, với dấu ngoặc kép, bạn có thể đặt biến trực tiếp bên trong các trích dẫn:

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    2

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Cả hai phương pháp đều hoạt động tốt, nhưng sử dụng dấu ngoặc kép có thể giúp bạn tiết kiệm một số rắc rối.

    Mẹo chuyên nghiệp:

    Sử dụng niềng răng xoăn để chỉ định rõ ràng kết thúc của một tên biến khi phân tích cú pháp nó vào một chuỗi được trích dẫn kép.

    Cố gắng in & nbsp; 2 cốc trên dòng 2 bên dưới sẽ cho bạn một lỗi vì mã cho rằng tên biến là & nbsp; $ unter_cups & nbsp; thay vì

    $recipe_title = 'Meatball Spaghetti';
    
    4:

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    3

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Để tránh các lỗi như thế này, bạn có thể bao quanh tên biến trong các dấu ngoặc xoăn thích như vậy:

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    4

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Bạn cũng có thể thực hiện một số hoạt động phức tạp hơn ngay trong các trích dẫn kép, nhưng điều đó nằm ngoài phạm vi của bài viết này. Để tìm hiểu thêm về các hoạt động phân tích phức tạp trong các báo giá kép, hãy xem các ví dụ trong hướng dẫn sử dụng PHP.

    -

    Nhân tiện, giống như các trích dẫn đơn, bạn có thể thêm các lần ngắt dòng vào đầu ra của mình bằng cách bao gồm các lần ngắt dòng trong chuỗi. Ví dụ,

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    5

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    displays:

    I am a geek.
    It'll be interesting to know about the string.
    This is a simple string.
    The word is ABC.
    6

    Nhập chế độ FullScreenen EXIT Mode FullScreen

    Nhân vật đặc biệt và ký tự thoát có trích dẫn đôi

    Double Trích dẫn cung cấp cho bạn nhiều nhân vật đặc biệt hơn để làm việc với các trích dẫn đơn lẻ, bao gồm cả ký tự phá vỡ dòng.

    • $recipe_title = 'Meatball Spaghetti';
      
      5 cho một dòng mới
    • $recipe_title = 'Meatball Spaghetti';
      
      6 cho một tab
    • $recipe_title = 'Meatball Spaghetti';
      
      7 để trở về vận chuyển
    • $recipe_title = 'Meatball Spaghetti';
      
      8 cho một dấu hiệu đô la (nếu không nó có thể bị nhầm là biến)
    • $recipe_title = 'Meatball Spaghetti';
      
      9 cho một báo giá kép
    • Xem thêm trong hướng dẫn sử dụng PHP

    Tôi nên sử dụng những gì?

    Nói chung, bạn sử dụng hoặc, nhưng bạn nên phù hợp với loại bạn sử dụng và khi nào. Ví dụ: bạn có thể chọn sử dụng các báo giá đơn theo mặc định trừ khi bạn cần sử dụng các biến hoặc ký tự đặc biệt trong chuỗi.

    Bạn có thể nghĩ rằng vì các trích dẫn đôi cung cấp cho bạn nhiều tính năng hơn, nên tốt hơn nếu sử dụng chúng mọi lúc, nhưng các trích dẫn đơn lẻ có lẽ tốt hơn cho các chuỗi đơn giản vì bạn không cần phải thoát khỏi các ký tự đặc biệt như dấu hiệu đô la.

    Bạn có thể sử dụng các trích dẫn đơn trong PHP không?

    Trích dẫn đơn ¶ Cách đơn giản nhất để chỉ định một chuỗi là đặt nó trong các trích dẫn đơn (ký tự '). Để chỉ định một trích dẫn đơn theo nghĩa đen, hãy thoát nó bằng một dấu gạch chéo ngược (\). Để chỉ định một dấu gạch chéo ngược theo nghĩa đen, nhân đôi nó (\\).The simplest way to specify a string is to enclose it in single quotes (the character ' ). To specify a literal single quote, escape it with a backslash ( \ ). To specify a literal backslash, double it ( \\ ).

    Bạn có thể sử dụng trích dẫn đơn và trích dẫn kép trong PHP không?

    Nếu đó là một nhân vật đặc biệt, thì nó sẽ được xem xét như trong quá trình phân tích cú pháp chuỗi.Các chuỗi trong PHP có thể được chỉ định theo bốn cách khác nhau: trích dẫn đơn, trích dẫn kép, cú pháp HEREDOC và cú pháp NowDac.Các trích dẫn và trích dẫn kép là được sử dụng thường xuyên nhất.The single quoted and double quoted are the most frequently used.

    Tôi nên sử dụng trích dẫn đơn hay đôi?

    Trong tiếng Anh Hoa Kỳ, bạn phải sử dụng dấu ngoặc kép.Dấu một trích dẫn duy nhất được sử dụng cho báo giá trong báo giá.Trong tiếng Anh của Vương quốc Anh, việc sử dụng các dấu ngoặc đơn duy nhất phổ biến nhất, với dấu ngoặc kép cho các trích dẫn trong báo giá, mặc dù cách khác cũng được chấp nhận.Trích dẫn là gì?. Single quotation marks are used for quotes within quotes. In UK English, it's most common to use single quotation marks, with double quotation marks for quotes within quotes, although the other way around is acceptable too. What is a quote?

    Các chuỗi được sử dụng như thế nào trong PHP?

    Theo các hàm chuỗi trong PHP, trong các ngôn ngữ lập trình, các hàm chuỗi được sử dụng để sửa đổi một chuỗi hoặc kiến thức truy vấn về một chuỗi (một số làm cả hai) .... hàm độ dài (chuỗi) là ví dụ cơ bản nhất về hàm chuỗi.Độ dài của một chuỗi theo nghĩa đen được trả về bởi hàm này.to modify a string or query knowledge about a string (some do both).... The length (string) function is the most basic example of a string function. The length of a string literal is returned by this function.