Skip to content

Can't insert string with text by "$html->innertext(or plaintext) = ??" methods #2

@dnquinn

Description

@dnquinn

Hi, first of all thanks a lot for this library, is faster more than 4x time than original, use native php DOM its a good idea.

My problem is the inner text of

tag (for example) cant be change by native library functionality. For example, if i search all p tags in dom, and than try use innertext it call exception 'not valid html fragment', if i do try it with plaintext - its return plaintext="some text" in attributes of node.

Maybe its my bad and i do something wrong, but there part of this code in __set function repair stability:
case 'innertext': $value = preg_replace("/" . $this->innertext . "/", $value, $this->outertext); return $this->replaceNode($value);

P.s у меня ужасный английский, но на всякий случай написал на двух языках, вдруг кто-то англо говорящий столкнется с такой же проблемой. В общем, почему нормально не отрабатывает plaintext я не знаю, но innertext как я понял точно не отработает, если у ноды не будет дочернего элемента который можно изменить. Сам код я особо не шерстил да и опыта в ООП у меня еще маловато, потому и такое топорное решение через preg_replace но все же рабочее.

Может быть если более детальнее протестировать код Вы наткнетесь на ту-же ошибку и сможете ее исправить более элегантным способом.

Еще раз спасибо за это чудесную либу, в синтетических тестах реально выдает ровно 4 разовый прирост скорости.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions