PHP/Development/Explode implode — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 07:03, 26 мая 2010
Содержание
explode time
<?php
$stampmebaby = microtime();
$chunks = explode(" ", $stampmebaby);
$microseconds = $chunks[0];
echo $microseconds;
?>
Implode array elements
<?
$words[0] = "My";
$words[1] = "short";
$words[2] = "sentence.";
$sentence = implode(" ", $words);
print("$sentence<BR>");
?>
Imploding an Array
<html>
<head>
<title>Implode</title>
</head>
<body>
<?php
$contact_data = Array();
$contact_data[0][0] = "W";
$contact_data[0][1] = "W";
$contact_data[0][2] = "W";
$contact_data[0][3] = ".";
$contact_data[0][4] = "J";
$contact_data[0][5] = "A";
$contact_data[0][6] = "V";
$contact_data[0][7] = "A";
$contact_data[1][0] = 2;
$contact_data[1][1] = "S";
$contact_data[1][2] = ".";
$contact_data[1][3] = "C";
$contact_data[1][4] = "O";
$contact_data[1][5] = "M";
$contact_data[1][6] = 9;
$contact_data[1][7] = "";
$contact_data[2][0] = "A";
$contact_data[2][1] = "";
$contact_data[2][2] = "B";
$contact_data[2][3] = "C";
$contact_data[2][4] = "D";
$contact_data[2][5] = "E";
$contact_data[2][6] = 5;
$contact_data[2][7] = "5.555.5";
$str_export_data = "";
for($i = 0; $i < count($contact_data); $i++)
$str_export_data .= implode(",", $contact_data[$i]) . "\n";
print(str_replace("\n", "\n<br />", $str_export_data));
?>
</body>
</html>
Set Implode char
<?php
$cities = array("A", "B", "C", "D");
echo implode("|", $cities);
?>
Takes a string apart based on a delimiter
<html>
<head>
<title>Explode</title>
</head>
<body>
<?php
$raw_contact_data =
"A,,B,555 C,D,E,55555,555.555.5555\n"
. "F,,G,1010 H,I,J,99999\n"
. "Q,,R,555 S,T,U,5,55.5.5\n";
$contact_records = explode("\n", $raw_contact_data);
foreach($contact_records as $person)
{
$person_data = explode(",", $person);
foreach($person_data as $contact_item)
{
$contact_item = ucfirst($contact_item);
print("$contact_item ");
}
print("<br />\n");
}
?>
</body>
</html>