{"id":17305439,"url":"https://github.com/kovah/laravel-html-meta","last_synced_at":"2025-04-14T13:22:57.475Z","repository":{"id":57008779,"uuid":"345349462","full_name":"Kovah/laravel-html-meta","owner":"Kovah","description":"A simple helper to retrieve the HTML meta tags of a website.","archived":false,"fork":false,"pushed_at":"2025-02-24T20:11:05.000Z","size":69,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T00:45:29.693Z","etag":null,"topics":["html","laravel","laravel-package","meta-tags","parser"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kovah.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"kovah","patreon":"Kovah","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"kovah","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-03-07T13:08:17.000Z","updated_at":"2025-02-24T17:23:46.000Z","dependencies_parsed_at":"2022-08-21T14:31:36.751Z","dependency_job_id":"9dfb5092-788e-40a4-9067-522fce572bb1","html_url":"https://github.com/Kovah/laravel-html-meta","commit_stats":{"total_commits":33,"total_committers":2,"mean_commits":16.5,"dds":"0.030303030303030276","last_synced_commit":"ab4d2f1ded1e0dab8494a61e8c2b1e4ab6a7633d"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kovah%2Flaravel-html-meta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kovah%2Flaravel-html-meta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kovah%2Flaravel-html-meta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kovah%2Flaravel-html-meta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kovah","download_url":"https://codeload.github.com/Kovah/laravel-html-meta/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248886750,"owners_count":21177741,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","laravel","laravel-package","meta-tags","parser"],"created_at":"2024-10-15T11:55:42.340Z","updated_at":"2025-04-14T13:22:57.445Z","avatar_url":"https://github.com/Kovah.png","language":"PHP","funding_links":["https://github.com/sponsors/kovah","https://patreon.com/Kovah","https://liberapay.com/kovah"],"categories":[],"sub_categories":[],"readme":"# Laravel HTML Meta Package\n\n![Laravel Support: v9, v10, v11](https://img.shields.io/badge/Laravel%20Support-v9%2C%20v10%2C%20v11-blue) ![PHP Support: 8.x](https://img.shields.io/badge/PHP%20Support-8.0%2C%208.1%2C%208.2%2C%208.3%2C%208.4-blue)  \n![GitHub release (latest by date)](https://img.shields.io/github/v/release/kovah/laravel-html-meta) ![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/kovah/laravel-html-meta/test.yml?branch=main\u0026label=Tests) ![GitHub](https://img.shields.io/github/license/kovah/laravel-html-meta)\n\nThis package provides a simple helper to retrieve the HTML meta tags of a URL. It properly handles connection and client errors and converts the meta tag contents from the source encoding to UTF-8 if possible.\n\n\n## Installation \u0026 Usage\n\nYou can install this package via Composer:\n\n```\ncomposer require kovah/laravel-html-meta\n```\n\nLaravel automatically detects the package and makes it available in your application.\n\n\n## Usage\n\nThe `HtmlMeta` class is available as a facade and exposes the `forUrl` function. Here is a very basic example.\n\n```php\ntry {\n    $metaTags = \\Kovah\\HtmlMeta\\Facades\\HtmlMeta::forUrl('https://kovah.de')-\u003egetMeta();\n} catch (\\Kovah\\HtmlMeta\\Exceptions\\InvalidUrlException $e) {\n    // the provided URL is invalid\n} catch (\\Kovah\\HtmlMeta\\Exceptions\\UnreachableUrlException $e) {\n    // the website under this URL is not reachable\n}\n```\n\nThe `$metaTags` variable now contains the following data:\n\n```php\n[\n  \"title\" =\u003e \"Kovah.de - Web Development and Photography\",\n  \"generator\" =\u003e \"Hugo 0.58.2\",\n  \"viewport\" =\u003e \"width=device-width, initial-scale=1\",\n  \"description\" =\u003e \"Kovah - Web Development by Kevin Woblick\",\n  \"og:title\" =\u003e \"Kovah.de - Web Development by Kevin Woblick\",\n  \"og:description\" =\u003e \"Kovah - Web Development by Kevin Woblick\",\n  \"og:image\" =\u003e \"'https://kovah.de/kvh_social_1200x630.jpg'\",\n  \"og:url\" =\u003e \"'https://kovah.de/'/\",\n  \"og:site_name\" =\u003e \"Portfolio of Kevin Woblick\",\n  \"twitter:card\" =\u003e \"summary_large_image\",\n  // ...\n];\n```\n\nIf you want to use the response of the original request made to parse the HTML meta, you can get it with the `getResponse()` method like this:\n\n```php\n$metaResults = \\Kovah\\HtmlMeta\\Facades\\HtmlMeta::forUrl('https://kovah.de');\n\n$response = $metaResults-\u003egetResponse(); // Illuminate\\Http\\Client\\Response\n$metaTags = $metaResults-\u003egetMeta(); // array\n$url = $metaResults-\u003egetUrl(); // string\n```\n\n### Parsing HTML\n\nAs an alternative to fetching HTML from a URL, you might also parse HTML directly:\n\n```php\n$myHtml = '\u003c!DOCTYPE html\u003e\u003chead\u003e\u003cmeta name=\" twitter:description \" content=\"Text Value for Twitter Description\"\u003e ...';\n$metaTags = \\Kovah\\HtmlMeta\\Facades\\HtmlMeta::fromHtml($myHtml)-\u003egetMeta();\n```\n\nTo improve parsing and fallbacks, you might pass HTTP headers and the URL to the `fromHtml()` method like this:\n\n```php\n$myUrl = 'https://kovah.de';\n$httpHeaders = [\n    'content-type' =\u003e 'text/html; charset=iso-8859-1',\n];\n$myHtml = '\u003c!DOCTYPE html\u003e\u003chead\u003e\u003cmeta name=\" twitter:description \" content=\"Text Value for Twitter Description\"\u003e ...';\n$metaTags = \\Kovah\\HtmlMeta\\Facades\\HtmlMeta::fromHtml($myHtml, $httpHeaders, $myUrl)-\u003egetMeta();\n```\n\n\n## Configuration\n\nBy default, the package uses a 10 seconds timeout when trying to fetch the content of the URL. If you want to increase or decrease this timeout, you can publish the HTML Meta configuration.\n\n```\nphp artisan vendor:publish --provider=\"Kovah\\HtmlMeta\\HtmlMetaServiceProvider\"\n```\n\nThe configuration can now be found under `config/html-meta.php`.\n\n### Setting a custom User Agent\n\nThe package allows you to set one or more custom User Agents which will be used to send the requests. The User Agent(s) you want to use must be specified as an array in the package configuration html-meta.php like this:\n\n```php\n'user_agents' =\u003e [\n    'Mozilla/5.0 (Windows NT 6.4) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36.0',\n    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/…4.1.28 (KHTML, like Gecko) Version/15.2.0 Safari/604.1.28',\n    'Mozilla/5.0 (compatible; Googlebot/2.1.0; +http://www.google.com/bot.html)',\n]\n```\n\nThe HTML Meta package will randomly choose one of the User Agents for each request. If you want to use only one User Agent, remove all others from the list:\n\n```php\n'user_agents' =\u003e [\n    'Mozilla/5.0 (Windows NT 6.4) AppleWebKit/537.36.0 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36.0'\n]\n```\n\n### Adding more custom headers\n\nThe custom_headers configuration can contain any headers that should be added to any request, except User-Agent and Accept. It can be either an array of headers, or a pipe-separated string.\n\n\n```php\n'custom_headers' =\u003e [\n    'Accept-Encoding' =\u003e 'gzip, deflate',\n    'referer' =\u003e 'https://example.com',\n],\n```\n\nIf headers are passed as a string, the following format applies: `[header name]=[value]|[header name]=[value]|...`\n\nNote: Pipes inside the headers as a string must be escaped with a backslash.\n\n```php\n'custom_headers' =\u003e 'Accept-Encoding=gzip,deflate|referer=https://example.com'\n```\n\n\n## Parsing Details\n\nThe default parser shipping with this package extracts the meta tags from the HTML. These are the steps it is going through after the packages received a successful response:\n\n- All meta tags with `name` or `property` properties are parsed from the `\u003chead\u003e` section. The keys are converted to lowercase.\n- The `\u003ctitle\u003e` tag is parsed and all excessive white space is removed from the start and the end of it.\n- The package checks for a charset, which can be specified as:\n  - the HTML charset meta tag (`\u003cmeta charset=\"utf-8\"\u003e`),\n  - the HTTP content-type header (content-type: \"text/html; charset=utf-8\"),\n  - or as the HTML http-equiv=\"content-type\" tag (`\u003cmeta http-equiv=\"content-type\" content=\"text/html;\n  charset=utf-8\"\u003e`) We try to parse the charset in this exact order.\n- The value of all parsed meta tags is converted from the source charset (if available) to UTF-8, if it does not match UTF-8. **If the meta tag value cannot be converted, it is replaced by `null`!** The only exception is the title, which will be replaced by the hostname of the URL in case a conversion is not possible.\n- HTML entities such as `\u0026#8212;` are converted to the correct characters, in this example `—`.\n\n\n---\n\n\nThis package is a project by [Kevin Woblick](https://kovah.de) and [Contributors](https://github.com/Kovah/laravel-html-meta/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkovah%2Flaravel-html-meta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkovah%2Flaravel-html-meta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkovah%2Flaravel-html-meta/lists"}