Friday, November 7, 2014

PHP, separate string by any space or comma, lowercaser and timestamp in PHP and MySQl



PHP, separate string by any space or comma using regular expression
    // split the phrase by any number of commas or space characters,
       // which include " ", \r, \t, \n and \f
        $course_pieces = preg_split("/[\s,]+/", trim($course));

If you use explode, you can only separate by one space:
$course_pieces = explode(" ", trim($course));

In PHP, to convert to lower case:
        $course_subject = strtolower($course_pieces[0]);
        $course_number = $course_pieces[1];


While in MySQL, we use LOWER
for example
 $oplCondition = " AND  LOWER(FirstName) LIKE  LOWER('%".$firstname))."%')";

MySQL TIMESTAMP date type, corresponding to PHP function
date("Y-m-d  H:i:s")

No comments:

Post a Comment