0

I am trying to retrieve data from file_get_html($url).

$html = file_get_html($url);

foreach ($html->find("h1") as $key => $value){
echo $value."<br>";
}
foreach($html->$find("p") as $key => $edu){
echo $edu;
}

I am trying to fetch more than one value from the url. But I get this error message. I get the result for $value , but I get error with the next one.

Notice: Undefined variable: find in ...\parse.php on line 18

Fatal error: Method name must be a string in ...\parse.php on line 18

This is line 18

foreach($html->$find("p") as $key => $edu){

EDIT: Database Issue

$html = file_get_html($url);

foreach ($html->find("span[class=full-name]") as $key => $name){

echo $name."<br>";
}

Database looks like:

< span class="first-name" > Tony Stark

$result = mysqli_query($con,"INSERT INTO personal (name) VALUES ('$name')");
if (!$result){
    echo "Error!<br>";
}

1 Answer 1

1

The problem here is that you are using $html->$find("p") which in your case, find() is a method, but you treat it as a variable.

Try $html->find("p")

Hope it helps!
Keep on coding!
Ares.

Sign up to request clarification or add additional context in comments.

16 Comments

Ohh damn! A serious typing mistake and a serious negligence mistake. Thanks a lot, Ares.
One more query Ares, how do I use span class="xyz" in find method? syntax would be find(".'span class="xyz"'.") ???
I don't understand the question. please rephrase
You might be looking for something like this $html->find("span[class=xyz]") ??
In $html->find(), I would like to find this 'span class="college"'. How to write a proper syntax in html->find(" ").
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.