Php 删除给定格式中不需要的字符
我有一种字符串格式,可以删除不需要的字符,只使用时间格式。我的字符串是Php 删除给定格式中不需要的字符,php,regex,preg-match,Php,Regex,Preg Match,我有一种字符串格式,可以删除不需要的字符,只使用时间格式。我的字符串是10:02:in(user),可以删除所有字符,只使用10:02格式。如何删除?尝试使用substr $myStr = "10:02:in(user)"; echo $result = substr($myStr, 0, 5); 尝试使用substr $myStr = "10:02:in(user)"; echo $result = substr($myStr, 0, 5); explode()函数用于拆分字符串。 语法:
10:02:in(user)
,可以删除所有字符,只使用10:02格式。如何删除?尝试使用substr
$myStr = "10:02:in(user)";
echo $result = substr($myStr, 0, 5);
尝试使用substr
$myStr = "10:02:in(user)";
echo $result = substr($myStr, 0, 5);
explode()函数用于拆分字符串。
语法:
分解(分隔符、字符串名称、限制)
<?php
$str = "10:02:in(user)";
$new = explode(":", $str);
echo $new[0].":".$new[1];
?>
explode()函数用于拆分字符串。
语法:
分解(分隔符、字符串名称、限制)
<?php
$str = "10:02:in(user)";
$new = explode(":", $str);
echo $new[0].":".$new[1];
?>