从css注释php获取宽度


get width from css comments php

我有一个php字符串,如下面的

$str= ' <html>------- <style type="text/css">@media only screen and (max-width: 480px) { .message_mobile,.mesage_logo_mobile { width: 100% !important;} } .message_mobile{ width:600px;} /*message_width 600px */</style> -----</html>';

我需要从/*message_width 600px */读取600px。有可能从字符串中获得那个值吗?

if (preg_match('/'.message_mobile's*'{'s*width:'s*('d+)/s', $str, $tmp)) {
    $width = $tmp[1];
} else {
    $width = "not defined";
}

如果html不是由您生成的。为什么这么做?

$pos = strpos($str, '600px');
if ($pos === true) {
    [your code here];
}

这就是你要找的吗?strpos()函数。