I would like to know how can I take a character out of a string?
I have a date:
$date = "04.08.2013";
I would like to take just the first 2 zeros off. Like that:
$date = "4.8.2013"
How can I do it?
一个简洁的(读取:hacky)解决方案将是:
$date = implode('.', array_map(function($x) { return (int)$x; }, explode('.', $date)));
You can may also get it done quickly using a regex:
$new_date = preg_replace('/(?<=^|\.)0/', '', $date);
Or more simply without the lookbehind (thanks @IlmariKaronen):
$new_date = preg_replace('/\b0/', '', $date);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.