⊗ppPsDDCS 30 of 84 menu

CSS Selectors When Searching for an Element via DiDom in PHP

When selecting elements via DiDom, you can use various CSS selectors. Let's look at an example. Suppose we have the following HTML code:

<p class="eee"> --- </p> <p class="xxx"> +++ </p> <p class="zzz"> --- </p>

Let's find the element with the class .xxx:

<?php $elem = $document->first('.xxx'); ?>

Let's output its text:

<?php echo $elem->text(); // '+++' ?>

Output the text of the element with the id block:

<div> --- </div> <div id="block"> +++ </div> <div> --- </div>

Output the text of the element with the class elem:

<div> --- </div> <div class="elem"> +++ </div> <div> --- </div>

Output the text of the element with the class elem, located inside the element with the id block:

<p class="elem"> --- </p> <div id="block"> <p class="elem"> +++ </p> <p> --- </p> <p> --- </p> </div>

Get the element with the attribute type with the value text:

<input type="checkbox"> <input type="text">
byenru