Skip to content

Explained the DomCrawler charset guessing mechanism #8471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,19 @@ The crawler supports multiple ways of adding the content::

.. note::

When dealing with character sets other than ISO-8859-1, always add HTML
content using the :method:`Symfony\\Component\\DomCrawler\\Crawler::addHtmlContent`
method where you can specify the second parameter to be your target character
set.
The :method:`Symfony\\Component\\DomCrawler\\Crawler::addHtmlContent` and
:method:`Symfony\\Component\\DomCrawler\\Crawler::addXmlContent` methods
default to UTF-8 encoding but you can change this behavior with their second
optional argument.

The :method:`Symfony\\Component\\DomCrawler\\Crawler::addContent` method
guesses the best charset according to the given contents and defaults to
``ISO-8859-1`` in case no charset can be guessed.

.. versionadded:: 3.4
The charset guessing mechanism of the ``addContent()`` method was
introduced in Symfony 3.4. In previous Symfony versions, ``ISO-8859-1``
charset was always used.

As the Crawler's implementation is based on the DOM extension, it is also able
to interact with native :phpclass:`DOMDocument`, :phpclass:`DOMNodeList`
Expand Down Expand Up @@ -397,13 +406,13 @@ a :class:`Symfony\\Component\\DomCrawler\\Form` object that represents the
form that the button lives in::

// button example: <button id="my-super-button" type="submit">My super button</button>

// you can get button by its label
$form = $crawler->selectButton('My super button')->form();

// or by button id (#my-super-button) if the button doesn't have a label
$form = $crawler->selectButton('my-super-button')->form();

// or you can filter the whole form, for example a form has a class attribute: <form class="form-vertical" method="POST">
$crawler->filter('.form-vertical')->form();

Expand Down