Last active
February 24, 2021 10:45
-
-
Save karrikas/ae2da25dfef8aa8e64840b594391b8b1 to your computer and use it in GitHub Desktop.
Symfony Crawler how to add <option> to <select> element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\DomCrawler\Crawler; | |
$crawler = new Crawler('<html><body><select id="my_select"></select></body></html>'); | |
$crawler->filter('select#my_select')->each(function (Crawler $crawler) { | |
$node = $crawler->getNode(0); | |
$option = new \DOMElement('option', 'Option Name'); | |
$node->appendChild($option); | |
$option->setAttribute('value', 'Option Value'); | |
}); | |
echo $crawler->html(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment