Is it difficult to create an element and set the id to empty?

1

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;
}
    
asked by anonymous 28.08.2017 / 19:02

2 answers

0

According to W3 :

  

ID and NAME Tokens must start with a letter ([A-Za-z]) and can be   followed by any number of letters, digits ([0-9]), hyphens ("-"),   underscores ("_"), colon (":"), and endpoints (".").

According to this definition empty id's are not valid. While nothing will stop you from using them, you can not guarantee how browsers will render them.

    
28.08.2017 / 19:13
0

Problem does not exist if you do not need to reference the element ID in your project.

  

Regarding the response of the friend @Genos, although he mentioned the source of the    W3 , ID and NAME do not necessarily need to start with letter.

    
28.08.2017 / 19:43