note 114697 added to datetime.createfromformat

From: Date: Mon, 24 Mar 2014 18:46:45 +0000
Subject: note 114697 added to datetime.createfromformat
Groups: php.notes 
Request: Send a blank email to php-notes+get-199040@lists.php.net to get a copy of this message
Say if there is a string with $date = "today is 2014 January 1"; and you need to extract "2014 January" using DateTime::createFromFormat(). As you can see in the string there is something odd like "today is" .Since that string (today is) does not correspond to a date format, we need to escape that. In this case, each and every character on that string has to be escaped as shown below. The code. <?php $paragraph = "today is 2014 January 1"; $date = DateTime::createFromFormat('\t\o\d\a\y \i\s Y F j', $paragraph); echo $date->format('Y F'); //"prints" 2014 January - Shankar Damodaran ---- Server IP: 103.21.58.218 Probable Submitter: 59.92.12.27 ---- Manual Page -- http://php.net/manual/en/datetime.createfromformat.php Edit -- https://master.php.net/note/edit/114697 Del: integrated -- https://master.php.net/note/delete/114697/integrated Del: useless -- https://master.php.net/note/delete/114697/useless Del: bad code -- https://master.php.net/note/delete/114697/bad+code Del: spam -- https://master.php.net/note/delete/114697/spam Del: non-english -- https://master.php.net/note/delete/114697/non-english Del: in docs -- https://master.php.net/note/delete/114697/in+docs Del: other reasons-- https://master.php.net/note/delete/114697 Reject -- https://master.php.net/note/reject/114697 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199040) next »