igfs/kernel/helpers/Html.php

42 lines
973 B
PHP
Raw Permalink Normal View History

2024-12-16 14:26:13 +03:00
<?php
namespace kernel\helpers;
class Html
{
public static function img(string $src, array $params = [])
{
$paramsStr = self::createParams($params);
return "<img src='$src' $paramsStr>";
}
public static function h(string|int $type = 1, string $title = '', array $params = [])
{
$paramsStr = self::createParams($params);
return "<h$type $paramsStr>$title</h$type>";
}
public static function a(string $link, array $params = []): string
{
$paramsStr = self::createParams($params);
return "<a href='$link' $paramsStr>";
}
/**
* @param array $data
* @return string
*/
public static function createParams(array $data = []): string
{
$paramsString = "";
foreach($data as $key => $param){
if(is_string($param)){
$paramsString .= $key . "='" . $param . "'";
}
}
return $paramsString;
}
}