如何在php中获取字符串中的特定字符

时间:2016-03-19 06:11:10

标签: php mysqldump

我希望得到一个单词,直到一个spesicif字符,例如空格。我试图使用substr但我不能。

假设我有列数据:

1. 3/14/2016 13:46 

i would like to get 3/14/2016 and showing it. is that possible?



2. 3/14/2016 13:46 
i would like to get 13.46 without date. is that possible?

有人可以告诉我如何从2个案例中获取字符串。

非常感谢

2 个答案:

答案 0 :(得分:0)

如果列是以空格分隔的,那么您可以使用爆炸并拉出所需列的索引。

$rowData = "1. 3/14/2016 13:46";

$rowCols = explode(" ",$rowData);

echo $rowCols[1]; // returns 3/14/2016
echo $rowCols[2]; // returns 13:46

答案 1 :(得分:0)

$specifidCharacter = " " //Space for example
$string = "1. 3/14/2016 13:46";

$tmp = explode($specificCharacter, $string);
echo $tmp[1] //Case 1
echo $tmp[2] //Case 2