Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»PHP»PHP – Split a String into Array with Delimiter

    PHP – Split a String into Array with Delimiter

    RahulBy RahulMay 12, 20151 Min ReadUpdated:July 10, 2019

    While working with the php programming language, This article will help you to split comma, colon or any other delimited string in to array.

    Use php explode function to split delimited string to array.

    $myArray = explode(',', $myString);
    

    Example

    Create a php script file and use following code. This example code is using command (,) as delimiter. You can also use any other delimiter like colon (:), semi colon (;), slash (/) etc.

    PHP
    1
    2
    3
    4
    5
    6
    7
    8
    <?php
     
      $myString = "101,TecAdmin,[email protected],India";
      $myArray = explode(',', $myString);
      echo "<pre>";
      print_r($myArray);
     
    ?>

    Now access file in web browser and you will get following result.
    Output:

    Array
    (
        [0] => 101
        [1] => TecAdmin
        [2] => [email protected]
        [3] => India
    )
    
    array javastring PHP string
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Set Default Document in IIS
    Next Article How to Install JAVA 7 (JDK 7u79) on CentOS/RHEL 7/6/5 and Fedora

    Related Posts

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:May 9, 20223 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    5 Methods to Print an Array in Java

    Updated:April 21, 20222 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    How To Install and Use PHP Composer on Debian 11

    Updated:February 16, 20224 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.