$str = 'Hello';
print_r(str_split($str)); // array('H', 'e', 'l', 'l', 'o')
print_r(str_split($str, 3)); // array('Hel', 'lo')
$string = "11 22 33 44 55 66";
// " " 為要切割的基準點
$output = explode(" ", $string);
echo $output[0]; // 11
echo $output[1]; // 22
echo $output[2]; // 33
echo $output[3]; // 44
echo $output[4]; // 55
echo $output[5]; // 66
?>
$text = 'This is a {1} day, not {2} and {3}.';
$daytype = array( 1 => 'fine',
2 => 'overcast',
3 => 'rainy' );
while (ereg ('{([0-9]+)}', $text, $regs)) {
$found = $regs[1];
$text = ereg_replace("\{".$found."\}", $daytype[$found], $text);
}
echo "$text\n";
// This is a fine day, not overcast and rainy.
?>
|