开发者

Creating a regex for parsing screens resolutions

开发者 https://www.devze.com 2023-03-21 06:20 出处:网络
I have a 开发者_如何转开发string of text that somewhere will contain the resolution to my vid in the format ###x### or ####x#### (ex. 320x240 or ex. 1024x1280 ex. 320x1024 etc.) or any combo in betwee

I have a 开发者_如何转开发string of text that somewhere will contain the resolution to my vid in the format ###x### or ####x#### (ex. 320x240 or ex. 1024x1280 ex. 320x1024 etc.) or any combo in between. I am not great at regexes yet and I was wondering if anyone could point out where I am going wrong.

$res='some long string';
$search='/([0-9]{3-4})x([0-9]{3-4})/';
preg_match($search, $res, $matches);
$res1=$matches[1];
$res2=$matches[2];


It should be:

$search='/([0-9]{3,4})x([0-9]{3,4})/';


You can also use:

$search='/([1-9]\d{2,3})x([1-9]\d{2,3})/';

(more specific)

0

精彩评论

暂无评论...
验证码 换一张
取 消