0

I have a php string like bellow,

$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>';

I need to read 600px from /*message_width 600px */ Is it possible to get that value from the string?

Shijin TR
  • 7,516
  • 10
  • 55
  • 122
  • This might help you .. http://stackoverflow.com/questions/1935918/php-substring-extraction-get-the-string-before-the-first-or-the-whole-strin – Chella Oct 29 '14 at 06:34

2 Answers2

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

that if html was generated not by you. What's the reason do this?

Vasiliy vvscode Vanchuk
  • 7,007
  • 2
  • 21
  • 44
-1
$pos = strpos($str, '600px');

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

Is this what you're looking for? strpos() function.

FortMauris
  • 167
  • 7