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...">
)

HTMLHelper.URLFriendly

Converts a string to a URL friendy format

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

// Initialize an HTMLHelper
$htmlHelper = new HTMLHelper();

$string = "PHP-Berry framework for PHP backend applications";

// Convert $string to url friendly and print it
print $htmlHelper->URLFriendly($string);

The above code output is:

php-berry-framework-for-php-backend-applications
Clone this wiki locally