PHP split string and output array character example _php tutorial

Source: Internet
Author: User

PHP split string and output array character example


The explode () function can be used in the split character function in PHP, but there must be a rule for using this function, such as separating by | or separating with other characters, so that we can use explode to divide the string into arrays and then use the for traversal output, here are a few examples.

The explode () function splits the string into arrays.

Grammar

Explode (Separator,string,limit)

Example One

The code is as follows

$test = ' 472347127,893372115,850965403 ';
$r =explode (",", $test);
for ($i =0; $i<>
{echo $i. ". $r [$i]." ";}
?>

Output: 0.472347127 1.893372115 2.850965403

Example Two

The code is as follows

$a = "893372115,472347127,850965403";
$b =explode (",", $a);
foreach ($b as $BB)
{echo $bb. "";//print_r ($b);}
?>

Output: 893372115 472347127 850965403 PHP

Comma-delimited string

Using the explode function to split a string into an array

code as follows

$source = "HELLO1,HELLO2,HELLO3,HELLO4,HELLO5";//separate strings by commas
$hello = Explode (', ', $source);

for ($index =0; $index
echo $hello [$index];echo]
";
}

?>

Split function for character segmentation

The code is as follows

The delimiter can be a slash, a dot, or a horizontal line
$date = "04/30/1973";
List ($month, $day, $year) = Split (' [/.-] ', $date);
echo "Month: $month; Day: $day; Year: $year
n ";
?>

http://www.bkjia.com/PHPjc/873237.html www.bkjia.com true http://www.bkjia.com/PHPjc/873237.html techarticle PHP split string and output array character example the split character function in PHP can use the explode () function, but there must be a rule to use this function, such as by | separating or using other words ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.