Skip to content

Instantly share code, notes, and snippets.

@JPustkuchen
Last active February 12, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPustkuchen/ab6a7e7536da06a4bb5c403cea137c69 to your computer and use it in GitHub Desktop.
Save JPustkuchen/ab6a7e7536da06a4bb5c403cea137c69 to your computer and use it in GitHub Desktop.
PHP regex extraxt min-width / max-width from CSS MediaQuery
<?php
function getMinMaxFromMediaQuery($mediaQuery) {
$re = '/\d*(min-width|max-width):\s*(\d+\s?)(px|em|rem)/';
preg_match_all($re, $mediaQuery, $matches, PREG_SET_ORDER, 0);
$result = array();
if (!empty($matches)) {
if (count($matches) <= 2) {
foreach ($matches as $match) {
if (count($match) == 4) {
$result[] = [
'mediaQuery' => $mediaQuery,
'type' => $match[1], // min-width / max-width
'size' => $match[2], // 1200
'unit' => $match[3], // px
];
}
}
}
}
return $result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment