PHP/String/split — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 07:07, 26 мая 2010

Generating date-based drop-down menu options

 
<?php
list($hour, $minute, $second, $month, $day, $year) = split(":", date("h:i:s:m:d:Y"));
for ($i = 0; $i < 7; ++$i) {
    $timestamp = mktime($hour, $minute, $second, $month, $day + $i, $year); 
    $date = date("D, F j, Y", $timestamp);
    print "<option value="$timestamp">$date</option>\n";
}
?>



split() function divides a string into various elements.

 
Its syntax is: array split (string pattern, string string [, int limit])
<?
$ip = "123.456.789.000";      
$iparr = split ("\.", $ip);   
                              
print "$iparr[0] <br>";       
print "$iparr[1] <br>";       
print "$iparr[2] <br>";       
print "$iparr[3] <br>";       
?>



split.php

 
<?php
   $text = "this is\tsome text that\nwe might like to parse.";
   print_r(split("[\n\t]",$text));
?>



Use split() to limit a parameter to restrict division of $ip

 
<?
$ip = "123.456.789.000";      
$iparr = split ("\.", $ip, 2); 
                               
print "$iparr[0] <br>";        
print "$iparr[1] <br>";        
?>