Download the PHP package paslandau/guzzle-auto-charset-encoding-subscriber without Composer

On this page you can find all versions of the php package paslandau/guzzle-auto-charset-encoding-subscriber. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package guzzle-auto-charset-encoding-subscriber

DEPRECATED ⛔

This repository has been deprecated as of 2019-01-27. That code was written a long time ago and has been unmaintained for several years. Thus, repository will now be archived. If you are interested in taking over ownership, feel free to contact me.


guzzle-auto-charset-encoding-subscriber

Build Status

Plugin for Guzzle 4/5 to automatically convert the body of a reponse according to a predefined charset.

Description

Getting charsets right is hard. In a perfect world, everybody would use unicode (UTF-8) as character encoding for textual web content but that's just not gonna happen in the near future, so we have to deal with a lot of different encodings in the wild. Unfortunately that's another layer of complexity on top of my application and I really just want it to "work right".

I'm using Guzzle as an underlying library for dealing with HTTP requests and my whole application relies on content beeing encoded in UTF-8. In my locale (Germany) ISO-8859-1 is still widely used and it really messes up the content of an HTTP response, because Guzzle won't automatically convert ISO-8859-1 to my internally used UTF-8. So I decided to write this little plugin to convert any input encoding automatically to another output encoding. Headers and meta tags can be optionally adjusted as well.

Basic Usage

Requirements

Installation

The recommended way to install guzzle-auto-charset-encoding-subscriber is through Composer.

curl -sS https://getcomposer.org/installer | php

Next, update your project's composer.json file to include GuzzleAutoCharsetEncodingSubscriber:

{
    "repositories": [ { "type": "composer", "url": "http://packages.myseosolution.de/"} ],
    "minimum-stability": "dev",
    "require": {
         "paslandau/guzzle-auto-charset-encoding-subscriber": "dev-master"
    }
    "config": {
        "secure-http": false
    }
}

Caution: You need to explicitly set "secure-http": false in order to access http://packages.myseosolution.de/ as repository. This change is required because composer changed the default setting for secure-http to true at the end of february 2016.

After installing, you need to require Composer's autoloader:

Examples

Let's have a look a the differences between a 'normal' guzzle request and a request with a guzzle-auto-charset-encoding-subscriber at first:

Output (assuming your editor uses UTF-8 as default)

Using unmodified Guzzle request
Request to http://www.myseosolution.de/scripts/encoding-test.php?enc=iso:
Content-Type: text/html; charset=iso-8859-1; someOtherRandom="header in here"

<!DOCTYPE html>
<html>
    <head>
        <meta charset="iso-8859-1">
        <title>Umlauts everywhere �������</title>
    </head>
    <body>
        <h1>�������</h1>

    </body>
</html>

Using guzzle-auto-charset-encoding-subscriber
Request to http://www.myseosolution.de/scripts/encoding-test.php?enc=iso:
Content-Type: text/html; charset=utf-8; someOtherRandom="header in here"

<!DOCTYPE html>
<html>
    <head>
        <meta charset='utf-8' >
        <title>Umlauts everywhere öäüßÖÄÜ</title>
    </head>
    <body>
        <h1>öäüßÖÄÜ</h1>

    </body>
</html>

The requested website delivers content in the ISO-8859-1 encoding. The unmodified guzzle request passes exactly what it gets from the website back to us. If we're expecting UTF-8 encoded content, we will get the "garbage" result shown above, since the german umlauts won't be recognized. Using the guzzle-auto-charset-encoding-subscriber will convert the result from the encoding it finds in either the content-type header or the websites meta tags. To minimize compatibility issues on subsequent components, the plugin also adjusted the content-type header and the <meta charset='..'> tag to UTF-8.

The behaviour of the plugin can be modified as follows:

Adjust the content-type header

By default, the content-type header is adjusted when the guzzle-auto-charset-encoding-subscriber converts the body of a request into another encoding. You can prevent this behaviour by setting the $replaceHeaders parameter to false:

Adjust the meta tags

By default, the content of a document is not modified (apart from being converted into another encoding). You can explicitly force the guzzle-auto-charset-encoding-subscriber to adjust the meta tags within a document to reflect the new encoding by setting the $replaceContent parameter to true:

Currently, 3 different cases are handled/recognized:

Forcing a default input encoding

Some websites use no (or wrong) values for the content-type header or the meta tags. In those cases, the guzzle-auto-charset-encoding-subscriber can be configured to assume a default encoding:

Related plugins

Frequently searched questions


All versions of guzzle-auto-charset-encoding-subscriber with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
ext-mbstring Version *
paslandau/web-utility Version ~0.8
guzzlehttp/guzzle Version ^5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package paslandau/guzzle-auto-charset-encoding-subscriber contains the following files

Loading the files please wait ....