我有一个字符串
$dim = "64×191×75"
此字符串基本上是宽度x高度x深度。我想分离价值观。 我写的代码是:
<?php
$dim = "64×191×75"
preg_match_all("'x(.*?)x'si",$dim,$dim_h);
$dimension['height'] = $dim_h[1][0];
$dimension['width'] = strstr($dim,'x',true);
$dimension['depth'] = substr(strrchr($dim,"x"),1);
var_dump($dimension);
exit();
This is Dump. I get along with a Notice. That Offset for $dim_h doesn't exist.
array (size=3)
'height' => null
'width' => boolean false
'depth' => boolean false
我无法找到字符串函数不起作用的任何原因。但不确定pregmatch。非常感谢帮助。
答案 0 :(得分:1)
简单方法:
$dim = "64×191×75";
$tmp = explode('x', $dim, 3);
$dimension['height'] = $tmp[0];
$dimension['width'] = $tmp[1];
$dimension['depth'] = $tmp[2];