Page MenuHomeDevCentral

D717.id1804.diff
No OneTemporary

D717.id1804.diff

diff --git a/page.php b/page.php
--- a/page.php
+++ b/page.php
@@ -196,45 +196,34 @@
* @return array an array where the keys are the metatags' names and the values the metatags' values
*/
function get_all_meta_tags () {
- //Thank you to Michael Knapp and Mariano
- //See http://php.net/manual/en/function.get-meta-tags.php comments
- preg_match_all('/<[\s]*meta[\s]+.*?\b(name|property|itemprop)\b="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $this->data, $match);
- if (isset($match) && is_array($match) && count($match) == 4) {
- $originals = $match[0];
- $names = $match[2];
- $values = $match[3];
-
- if (count($originals) == count($names) && count($names) == count($values)) {
- $metaTags = array();
-
- for ($i = 0, $limiti = count($names) ; $i < $limiti ; $i++) {
- $key = $names[$i];
- $value = $values[$i];
-
- //Sets an unique scalar value, or if several identical tag names are offered, an array of values.
- //Some publishers offer several times the same tag to list several values (see T241).
- if (array_key_exists($key, $metaTags)) {
- $currentValue = $metaTags[$key];
- if ($currentValue == $value) {
- continue;
- }
- if (is_array($currentValue)) {
- $metaTags[$key][] = $value;
- } else {
- //Scalar -> array
- $metaTags[$key] = [ $currentValue, $value ];
- }
- } else {
- $metaTags[$key] = $value;
- }
- }
- }
- }
-
- array_walk($metaTags, [ self, clean_tag ]);
-
- return $metaTags;
- }
+ // Thank you to Bobble Bubble
+ // See http://php.net/manual/en/function.get-meta-tags.php comments
+ $pattern = '
+ ~<\s*meta\s
+
+ # Lookahead to capture type to $1
+ (?=[^>]*?
+ \b(?:name|property|itemprop|http-equiv)\s*=\s*
+ (?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
+ ([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
+ )
+
+ # Capture content to $2
+ [^>]*?\bcontent\s*=\s*
+ (?|"\s*([^"]*?)\s*"|\'\s*([^\']*?)\s*\'|
+ ([^"\'>]*?)(?=\s*/?\s*>|\s\w+\s*=))
+ [^>]*>
+
+ ~ix';
+
+ if (!preg_match_all($pattern, $this->data, $match)) {
+ return [];
+ }
+
+ $metaTags = array_combine($match[1], $match[2]);
+ array_walk($metaTags, 'self::clean_tag');
+ return $metaTags;
+ }
/**
* Cleans a tag value (callback for array_walk)

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 19, 08:52 (20 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2252293
Default Alt Text
D717.id1804.diff (2 KB)

Event Timeline