I want to create a php function that creates html elements in a more agile way, the syntax should be more or less as an extension of the sublime
create("p#paragrafo.classe1.classe2.classe3=content");
a saida devera ser: <p id="paragrafo" class="classe1 classe2 classe3">content</p>
Only if I pass p#.classe1=content
it will create <p id="" class="classe1">content</p>
. Is it okay to stay that id=""
?
The finished function:
function create ($str) {
$text = substr($str, strpos($str, "=") + 1);
$close = "";
$str = str_replace("=$text", "", $str);
for ($i = 0, $j = substr_count($str, ">") + 1; $i < $j; $i++) {
# substring
$substr = ($pos = strpos($str, ">"))?substr($str, 0, $pos):$str;
# posicao id
$posId = strpos($substr, "#");
# posicao class
$posClass = strpos($substr, ".");
# tag
$tag = substr($substr, 0, $posId);
# id
$id = substr($substr, $posId + 1, $posClass - $posId - 1);
# class
$class = str_replace(".", " ", substr($substr, $posClass + 1));
# nao sei o que comentar
$close = "/$tag$close";
$str = str_replace("$substr>", "", $str);
# saida
echo "$tag class='$class' id='$id'";
echo "<br><br>";
}
# saida
echo $text;
echo "<br><br>";
echo $close;
}