Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.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 删除给定格式中不需要的字符_Php_Regex_Preg Match - Fatal编程技术网

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];
?>