Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从PHP字符串中去除unix时间戳_Php_Regex_Unix_Timestamp - Fatal编程技术网

如何从PHP字符串中去除unix时间戳

如何从PHP字符串中去除unix时间戳,php,regex,unix,timestamp,Php,Regex,Unix,Timestamp,假设我有以下字符串: $string = 'Th1s 1s my 5tr1ng with a timestamp 1357002120 and another timestamp here 1357002120.'; 我想要的是返回一个字符串,不带两个时间戳,但保留任何其他数字不变 因此,输出应为: “这是我的5次尝试,在这里有一个时间戳和另一个时间戳。” 我想某种类型的正则表达式可以做到这一点,但我不知道从哪里开始。简单的解决方案您可以稍后开发自己的: <?php $string =

假设我有以下字符串:

$string = 'Th1s 1s my 5tr1ng with a timestamp 1357002120 and another timestamp here 1357002120.';
我想要的是返回一个字符串,不带两个时间戳,但保留任何其他数字不变

因此,输出应为:

“这是我的5次尝试,在这里有一个时间戳和另一个时间戳。”


我想某种类型的正则表达式可以做到这一点,但我不知道从哪里开始。

简单的解决方案您可以稍后开发自己的:

<?php
$string = 'Th1s 1s my 5tr1ng with a timestamp 1357002120 and another timestamp here 1357002120.';
echo preg_replace("#\d{10,11}#", "", $string);
?>

简单的解决方案您可以在以后开发自己的解决方案:

<?php
$string = 'Th1s 1s my 5tr1ng with a timestamp 1357002120 and another timestamp here 1357002120.';
echo preg_replace("#\d{10,11}#", "", $string);
?>


我们如何确定另一个数字不是
时间戳
?如何定义UNIX时间戳?只是被单词边界包围的数字吗?因为
1
-40
也是UNIX时间戳。这一点非常好,老实说,我没有考虑过。应用程序中的要求范围是时间戳必须在过去7天内。因此,我想我们可以安全地假设它是10位长的,为了论证起见,让我们假设每10或11位长的数值就是这个变量中的时间戳。我们如何确定另一个数字不是时间戳?如何定义UNIX时间戳?只是被单词边界包围的数字吗?因为
1
-40
也是UNIX时间戳。这一点非常好,老实说,我没有考虑过。应用程序中的要求范围是时间戳必须在过去7天内。所以,我想我们可以安全地假设它是10位长的,为了论证起见,让我们假设每10或11位长的数值就是这个变量中的时间戳。