Download the PHP package kovah/laravel-html-meta without Composer
On this page you can find all versions of the php package kovah/laravel-html-meta. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-html-meta
Laravel HTML Meta Package
This 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.
Installation & Usage
You can install this package via Composer:
Laravel automatically detects the package and makes it available in your application.
Usage
The HtmlMeta
class is available as a facade and exposes the forUrl
function. Here is a very basic example.
The $metaTags
variable now contains the following data:
If 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:
Parsing HTML
As an alternative to fetching HTML from a URL, you might also parse HTML directly:
To improve parsing and fallbacks, you might pass HTTP headers and the URL to the fromHtml()
method like this:
Configuration
By 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.
The configuration can now be found under config/html-meta.php
.
Setting a custom User Agent
The 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:
The 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:
Adding more custom headers
The 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.
If headers are passed as a string, the following format applies: [header name]=[value]|[header name]=[value]|...
Note: Pipes inside the headers as a string must be escaped with a backslash.
Parsing Details
The 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:
- All meta tags with
name
orproperty
properties are parsed from the<head>
section. The keys are converted to lowercase. - The
<title>
tag is parsed and all excessive white space is removed from the start and the end of it. - The package checks for a charset, which can be specified as:
- the HTML charset meta tag (
<meta charset="utf-8">
), - the HTTP content-type header (content-type: "text/html; charset=utf-8"),
- or as the HTML http-equiv="content-type" tag (
<meta http-equiv="content-type" content="text/html; charset=utf-8">
) We try to parse the charset in this exact order.
- the HTML charset meta tag (
- 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. - HTML entities such as
—
are converted to the correct characters, in this example—
.
This package is a project by Kevin Woblick and Contributors
All versions of laravel-html-meta with dependencies
ext-iconv Version *
guzzlehttp/guzzle Version ^7.2
illuminate/http Version ^9.0 | ^10.0 | ^11.0
illuminate/support Version ^9.0 | ^10.0 | ^11.0