2013年11月15日 星期五

PHP 常用的東西

// foreach syntax
foreach($names as $person){
 echo $person;
}

//get now ...
print_r(date('Y-m-d'));
echo '<br/>';
print_r(date('H-i-s'));

//To splite a string.
$parts = explode(' ',$sentence); //like splite.

//To finds a substring position in a string.
$sentence = 'This is totorial number 21';
$needle = 'n';
$search = strpos($sentence, $needle);
if($search === FALSE)
 echo 'not found';
else
 echo 'The position of the string is '. $search;

//Reading a file content.
$file = './document.txt';
$doc = file_get_contents($file);

//Writing the content to a file.
$file = './lines.txt';
$write = 'This is line one\n';
file_put_contents($file, $write);




沒有留言:

張貼留言