Skip to content

Instantly share code, notes, and snippets.

@jmdrawneek
Created November 22, 2017 14:22
Show Gist options
  • Save jmdrawneek/2f70de482281008d61413981860b6b36 to your computer and use it in GitHub Desktop.
Save jmdrawneek/2f70de482281008d61413981860b6b36 to your computer and use it in GitHub Desktop.
function _f10_update_makrup_attribute ($content, $xpath_target, $values) {
$dom = new DOMDocument();
$dom->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
// Evaluate P tags in HTML. This just shows
// that you can be more selective on your tags
$xpath = new DOMXPath($dom);
$tags = $xpath->evaluate("//" . $xpath_target);
// Loop through all the found tags
foreach ($tags as $tag) {
// Set class attribute
$classes = $tag->getAttribute("class");
$tag->setAttribute("class", $values . ' ' . $classes);
}
$returnedHTML = $dom->saveHTML();
// Save the HTML changes
return $returnedHTML;
}
What goes in:
<li class='gchoice_6_1_0'>
<input name='input_1' type='radio' value='I don&#039;t like cooking, it&#039;s takeaways and ready meals for me' id='choice_6_1_0' tabindex='1' />
<label for='choice_6_1_0' id='label_6_1_0'>I don't like cooking, it's takeaways and ready meals for me</label>
</li>
<li class='gchoice_6_1_1'>
<input name='input_1' type='radio' value='I don&#039;t mind cooking but time is tight, quick and simple' id='choice_6_1_1' tabindex='2' />
<label for='choice_6_1_1' id='label_6_1_1'>I don't mind cooking but time is tight, quick and simple</label>
</li>
<li class='gchoice_6_1_2'>
<input name='input_1' type='radio' value='I enjoy cooking and try and find the time' id='choice_6_1_2' tabindex='3' />
<label for='choice_6_1_2' id='label_6_1_2'>I enjoy cooking and try and find the time</label>
</li>
<li class='gchoice_6_1_3'>
<input name='input_1' type='radio' value='I love cooking and always make the time to cook' id='choice_6_1_3' tabindex='4' />
<label for='choice_6_1_3' id='label_6_1_3'>I love cooking and always make the time to cook</label>
</li>
What comes out:
<li class="hero-quiz__list-item gchoice_6_1_0">
<input name="input_1" type="radio" value="I don't like cooking, it's takeaways and ready meals for me" id="choice_6_1_0" tabindex="1">
<label for="choice_6_1_0" id="label_6_1_0">I don't like cooking, it's takeaways and ready meals for me</label>
<li class="hero-quiz__list-item gchoice_6_1_1">
<input name="input_1" type="radio" value="I don't mind cooking but time is tight, quick and simple" id="choice_6_1_1" tabindex="2">
<label for="choice_6_1_1" id="label_6_1_1">I don't mind cooking but time is tight, quick and simple</label>
</li>
<li class="hero-quiz__list-item gchoice_6_1_2">
<input name="input_1" type="radio" value="I enjoy cooking and try and find the time" id="choice_6_1_2" tabindex="3">
<label for="choice_6_1_2" id="label_6_1_2">I enjoy cooking and try and find the time</label>
</li>
<li class="hero-quiz__list-item gchoice_6_1_3">
<input name="input_1" type="radio" value="I love cooking and always make the time to cook" id="choice_6_1_3" tabindex="4">
<label for="choice_6_1_3" id="label_6_1_3">I love cooking and always make the time to cook</label>
</li>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment