【问题标题】:get width from css comments php从css评论php中获取宽度
【发布时间】:2014-12-24 18:47:39
【问题描述】:

我有一个像下面这样的 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 是否可以从字符串中获取该值?

【问题讨论】:

标签: php html string


【解决方案1】:
$pos = strpos($str, '600px');

if ($pos === true) {
    [your code here];
}

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

【讨论】:

  • 他想从 css 属性中获取值,而不是检查子字符串是否存在
【解决方案2】:
if (preg_match('/\.message_mobile\s*\{\s*width:\s*(\d+)/s', $str, $tmp)) {
    $width = $tmp[1];
} else {
    $width = "not defined";
}

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

【讨论】:

    猜你喜欢
    • 2012-03-06
    • 2014-03-23
    • 1970-01-01
    • 2016-03-21
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    相关资源
    最近更新 更多