preg_replace中的正则表达式

时间:2016-01-02 16:27:01

标签: php regex

您好我是PHP的正则表达式新手

我尝试找出一条可以向MySQL插入数据的字样,该字段是" timestamp"

$string1 = "7/1/2015, 19:42:52"; 
$string2 = "12/12/2015, 1:08:17"; 
$string1 = preg_replace("/\//",'-',$string); 
$string2 = preg_replace("/\//",'-',$string);

这一步将如下:

7-1-2015, 19:42:52
12-12-2015, 1:08:17

如果我整理出来(包括ZEROFILL)就像:

string1 = 2015-07-01 19:42:52
string2 = 2015-12-12 01:08:17

我该怎么做..?

1 个答案:

答案 0 :(得分:6)

快速又脏,但结果你已经拥有了,你可以这样做:

$(function ()
{
  $('td').filter(function ()
  {
    var contents = $(this).contents();
    return contents.length == 1 && contents[0].nodeType == 3;
  }).mouseover(function ()
  {
    var $this = $(this);
    var $control = $this.next().find(':first-child');
    if ($control.attr('id').indexOf('UI') == 0)
    {
      var offset = $control.offset();
      $('#tooltip').css({
        top: offset.top + 'px',
        left: (offset.left + $control.width()) + 'px'
      }).show();
    }
  }).mouseout(function (e)
  {
    $('#tooltip').hide();
  });
});

这将为您提供预期的格式:echo date('Y-m-d H:i:s', strtotime('7-1-2015, 19:42:52'));

相关问题