Php 从用户提供的数据中拆分数字和单词

Php 从用户提供的数据中拆分数字和单词,php,Php,我的index.php文件中有以下代码 <?php $string = $_GET['string']; $month = ''; $day = ''; ?> 如果字符串类似于“apr12”或“12apr”, 那么$month应该是“apr”,而$day应该是“12” 否则,$month和$day都应为空。您可以使用day仅为数字,month仅为字符这一事实,因此它可能如下所示: $string = $_GET['string']; $month = strtolower(pr

我的index.php文件中有以下代码

<?php
$string = $_GET['string'];
$month = '';
$day = '';
?>

如果字符串类似于“apr12”或“12apr”, 那么$month应该是“apr”,而$day应该是“12”
否则,$month和$day都应为空。

您可以使用day仅为数字,month仅为字符这一事实,因此它可能如下所示:

$string = $_GET['string'];
$month = strtolower(preg_replace('/[^a-z]+/i','',$string));
$day = preg_replace('/[^0-9]+/','',$string);
if (!in_array($month, ['jan'/* ... and other valid values */], true)) {
  $month = '';
}
if ($day === '' || (int)$day < 1 || (int)$day > 31) {
  $day = '';
}
// Then validate your input further
$string=$\u GET['string'];
$month=strtolower(preg_replace('/[^a-z]+/i',''$string));
$day=preg_replace('/[^0-9]+/',''.$string);
如果(!in_数组($month,['jan'/*…和其他有效值*/],true)){
$month='';
}
如果($day==''||(int)$day<1|(int)$day>31){
$day='';
}
//然后进一步验证您的输入

您尝试了什么,或者只是想让我们帮您做?是的。到目前为止你试过什么?你的代码哪里出了问题。所以这不是一个代码编写服务。是的,对此我很抱歉。那太快了。多谢各位