php - String of file_get_html can't be edited?
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.
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.