Table of Contents

    Strings in PHP: Manipulation and Examples

    Strings in PHP: Manipulation and Examples

    PHP data types are used to hold different types of data or values. PHP supports the following data types:

    • String
    • Integer
    • Float
    • Boolean
    • Array
    • Object
    • NULL
    • Resource

    PHP String

    A string is a sequence of characters, like "Hello world!".

    A string can be any text inside quotes. You can use single or double quotes:

    Example code:

    
    <?php
    
    $x = "Hello world!";
    $y = 'Hello world!';
    
    echo $x;
    echo "<br>";
    echo $y;
    
    ?>
    
    

    Output:

    The above code will produce the following result-

    
    Hello world!
    Hello world!
    

    PHP Resource

    The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.

    A common example of using the resource data type is a database call.

    We will talk about the resource type in advanced topic.