Hướng dẫn dùng negative interval trong PHP
Hàm Cú phápCú pháp: Trong đó:
Kết quả trả vềHàm sẽ trả về khoảng thời gian đã được định dạng. Ví dụ về hàm Code $interval = date_interval_create_from_date_string('34 day'); echo date_interval_format($interval, '%d days'); Sự khác nhau giữa %a và %d: Code $january = date_create('2017-03-01'); $february = date_create('2017-04-01'); $interval = date_diff($february, $january); echo date_interval_format($interval, '%d days') . " Kết quả 3 days 31 days 1 month 3 days Tham khảo: php.net (PHP 4, PHP 5, PHP 7, PHP 8) strpos — Find the position of the first occurrence of a substring in a string Descriptionstrpos(string Parametershaystack The string to search in. needle Prior to PHP 8.0.0, if offset If specified, search will start this number of characters counted from the beginning of the string. If the offset is negative, the search will start this number of characters counted from the end of the string. Return Values Returns the position of where the needle exists relative to the beginning of the Returns
Warning This function may return Boolean Changelog
ExamplesExample #1 Using
Example #2 Using !==
Example #3 Using an offset
Notes
See Also
Suggested re-write for pink WARNING box ¶ 14 years ago
martijn at martijnfrazer dot nl ¶ 10 years ago
$found) { fabio at naoimporta dot com ¶ 6 years ago
var_dump(strpos("Fábio", 'b')) ; greg at spotx dot net ¶ 4 years ago
rjeggens at ijskoud dot org ¶ 10 years ago
mtroy dot student at gmail dot com ¶ 10 years ago
jexy dot ru at gmail dot com ¶ 5 years ago
m.m.j.kronenburg ¶ 6 years ago
$i = strlen($needle); $i > 0; $i--) usulaco at gmail dot com ¶ 12 years ago
$m[1] as $key => $value){
akarmenia at gmail dot com ¶ 11 years ago
eef dot vreeland at gmail dot com ¶ 5 years ago
ohcc at 163 dot com ¶ 8 years ago
bishop ¶ 18 years ago
Anonymous ¶ 9 years ago
Jean ¶ 3 years ago
marvin_elia at web dot de ¶ 4 years ago
digitalpbk [at] gmail.com ¶ 12 years ago
Achintya ¶ 12 years ago
strposq("he'llo'character;\"'som\"e;crap", ";"); //16
ilaymyhat-rem0ve at yahoo dot com ¶ 14 years ago
//String
spinicrus at gmail dot com ¶ 15 years ago
qrworld.net ¶ 7 years ago
Lurvik ¶ 8 years ago
false; gambajaja at yahoo dot com ¶ 12 years ago
yasindagli at gmail dot com ¶ 12 years ago
nth_position('foobarbaz', 'a', 2); //7 teddanzig at yahoo dot com ¶ 13 years ago
Tim ¶ 13 years ago
is_integer($i)){
$i = strpos($haystack,$needle,$s);
user at nomail dot com ¶ 15 years ago
if( $s2 === false ) { $s2 = $s1; } ah dot d at hotmail dot com ¶ 13 years ago
Lhenry ¶ 4 years ago
ds at kala-it dot de ¶ 2 years ago
FALSE !== strpos($str, 25)){ lairdshaw at yahoo dot com dot au ¶ 7 years ago
gjh42 - simonokewode at hotmail dot com ¶ 10 years ago
function strnposr($haystack, $needle, $occurrence, $pos = 0) { sunmacet at gmail dot com ¶ 1 year ago
philip ¶ 18 years ago
amolocaleb at gmail dot com ¶ 4 years ago
login(){ msegit post pl ¶ 4 years ago
hu60 dot cn at gmail dot com ¶ 3 years ago
' ';$now = date('H:i:s');if (isset($_SESSION['last_visit_time'])) { echo ' Last Visit Time: ' .$_SESSION['last_visit_time'].'';} echo ' Current Time: ' .$now.'';$_SESSION['last_visit_time'] = $now;function my_session_start() {global $phpsessid, $sessfile; if (!isset( $_COOKIE['PHPSESSID']) || empty($_COOKIE['PHPSESSID'])) {$phpsessid = my_base32_encode(my_random_bytes(16)); setcookie('PHPSESSID', $phpsessid, ini_get('session.cookie_lifetime'), ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly')); } else { $phpsessid = substr(preg_replace('/[^a-z0-9]/', '', $_COOKIE['PHPSESSID']), 0, 26); }$sessfile = ini_get('session.save_path').'/sess_'.$phpsessid; if (is_file($sessfile)) { $_SESSION = my_unserialize(file_get_contents($sessfile)); } else { $_SESSION = array(); } register_shutdown_function('my_session_save'); } function my_session_save() {global $sessfile;file_put_contents($sessfile, my_serialize($_SESSION)); } function my_session_id() {global $phpsessid; return $phpsessid; } function my_serialize($data) {$text = ''; foreach ($data as $k=>$v) { // key cannot contains '|' if (strpos($k, '|') !== false) { continue; } $text.=$k.'|'.serialize($v)."\n"; } return $text; } function my_unserialize($text) {$data = []; $text = explode("\n", $text); foreach ($text as $line) { $pos = strpos($line, '|'); if ($pos === false) { continue; } $data[substr($line, 0, $pos)] = unserialize(substr($line, $pos + 1)); } return $data; } function my_random_bytes($length) {if (function_exists('random_bytes')) { return random_bytes($length); } $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= chr(rand(0, 255)); } return $randomString; } function my_base32_encode($input) {$BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567'; $output = ''; $v = 0; $vbits = 0; for ($i = 0, $j = strlen($input); $i < $j; $i++) { $v <<= 8; $v += ord($input[$i]); $vbits += 8; while ($vbits >= 5) { $vbits -= 5; $output .= $BASE32_ALPHABET[$v >> $vbits]; $v &= ((1 << $vbits) - 1); } } if ($vbits > 0) { $v <<= (5 - $vbits); $output .= $BASE32_ALPHABET[$v]; } return $output; } binodluitel at hotmail dot com ¶ 8 years ago
|