php - How to remove everything behind the empty space? -


how can delete behind empty space. have date like: 10.10.2010 18:34 empty space between year , 18. need first part of string (only 10.10.2010). tried use preg_replace remove behind empty space, doesnt work. how expression have be?

thank help! phpheini

based on simple requirements, rather going full regex solution, can tokenize string using strtok()

$datepart = strtok($datestring, ' '); 

edit: reason see involve regular expressions validate date-time string @ same time extracting parts. example

if (preg_match('/(\d{1,2}\.\d{1,2}\.\d{4}) (\d{1,2}:\d{2})/', $datetimestring, $parts)) {     $date = $parts[1];     $time = $parts[2]; } else {     throw new exception('invalid date-time string format'); } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -