Skip to content

berry.utils.HTMLHelper

SourceRabbit edited this page Sep 30, 2022 · 12 revisions

HTMLHelper.GetHTMLTags

Returns an array with HTML objects of the given tag type contained in the given html string.

Example

The following example finds and prints all img tags within an html string.

require_once(__DIR__ . "/berry/utils.php"); // Include berry utils package

$htmlString = '<span>Hello this is an image <img src="myImage1.png" alt="Image"> and here is an other one <img src="myImage2.png" alt="An other one..."></span>';
$htmlHelper = new HTMLHelper();

// Get all <img> tags from $htmlString 
$images = $htmlHelper->GetHTMLTags("img", $htmlString);

print_r($images);

The above code output is:

Array
(
    [0] => <img src="myImage1.png" alt="Image">
    [1] => <img src="myImage2.png" alt="An other one...">
)
Clone this wiki locally