What is the difference between Plaintext and Innertext of an element in Simple HTML dom parser in PHP?

509

What is the difference between Plaintext and Innertext of an element in Simple HTML dom parser in PHP?

Example:

$html->find('title')[0]->innertext
$html->find('title')[0]->plaintext
65

Answer

Solution:

According to the Simple HTML DOM parser documentation the difference is next:

$html = str_get_html("<div>foo <b>bar</b></div>");
$e = $html->find("div", 0);

echo $e->tag; // Returns: " div"
echo $e->outertext; // Returns: " <div>foo <b>bar</b></div>"
echo $e->innertext; // Returns: " foo <b>bar</b>"
echo $e->plaintext; // Returns: " foo bar"
638

Answer

Solution:

Plaintext:

Plain text is used to find Element based on their tag names. Example: below example will find title. $html->find('title')[0]->plaintext

Innertext as name suggest Innertext is used to manipulate inner content of tags. Example: below example will find tag. $html->find('h1')[0]->innertext

People are also looking for solutions to the problem: php - Codeigniter 3 ajax calculating from another input using jquery

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.