php - String of file_get_html can't be edited?

84

Solution:

file_get_html() returns an object, not a string. Attempting to concatenate a string to an object will call the object's_toString() method if it exists, and the operation returns a string. Strings do not have afind() method.

If you want to do as you have described read the file contents and concatenate the extra string first:

$content = file_get_contents('someFile.html');
$content .= "someString";
$domObject  = str_get_html($content);

Alternatively, read the file withfile_get_html() and manipulate it with the DOM API.

910

Answer

Solution:

$doo is not a string! It's an object, an instance of Simple HTML DOM. You can't call-> methods on strings, only on objects. You cannot treat this object like a string. Trying to concatenate something to it makes no sense.$abd in your code is the result of an object concatenated with a string; this either results in a string or an error, depending in the details of the object. What it certainly does not do is result in a usable object, so you certainly can't do$abd->find().

If you want to modify the content of the page, do it using the DOM API which the object gives you.

People are also looking for solutions to the problem: php - Modify files in /vendor directory and commit changes to composer.lock?

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.