2014-10-29 65 views
0

寬度我有一個PHP串狀波紋管,得到CSS註釋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>'; 

我需要閱讀600px/*message_width 600px */是否有可能得到的字符串值?

+0

這可能會幫助你.. http://stackoverflow.com/questions/1935918/php-substring-extraction-get-the-string-before-the-first-or-the-whole-strin – Chella 2014-10-29 06:34:05

回答

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

如果html不是由您生成的。這是什麼原因?

-1
$pos = strpos($str, '600px'); 

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

這是你要找的嗎? strpos()函數。

+1

他想要從css屬性獲取值,而不是檢查是否存在子字符串 – 2014-10-29 06:37:55