PHP/String/split

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

Generating date-based drop-down menu options

   <source lang="html4strict">

<?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";

} ?>

 </source>
   
  


split() function divides a string into various elements.

   <source lang="html4strict">

Its syntax is: array split (string pattern, string string [, int limit]) <? $ip = "123.456.789.000"; $iparr = split ("\.", $ip);

print "$iparr[0]
"; print "$iparr[1]
"; print "$iparr[2]
"; print "$iparr[3]
"; ?>

 </source>
   
  


split.php

   <source lang="html4strict">

<?php

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

?>

 </source>
   
  


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

   <source lang="html4strict">

<? $ip = "123.456.789.000"; $iparr = split ("\.", $ip, 2);

print "$iparr[0]
"; print "$iparr[1]
"; ?>

 </source>