Jump to content

Getting HTML elements with PHP...


Raz0r

Recommended Posts

Yes it can be done. Depending on if you know exactly what you're searching for or not you might need to use PCRE functions, but for your specific example you could use strpos(). Example:

 

if(strpos($content, '<h1>This is my website</h1>') !== false)
{
     echo 'Found!'
}

 

Hmm....

You didn't understand me well., i think  :D

In your code, where is variable of website that will be checked for that code in HTML?

 

Link to comment
Share on other sites

Hmm....

You didn't understand me well., i think  :D

In your code, where is variable of website that will be checked for that code in HTML?

 

 

I think he explained it well for how you explained it. If that is not right, post 2 real examples that you would use so we can better understand what you want to be achieved. Given the original topic, Alex answered you question perfectly. Doing a better explanation with examples of what you want exactly will help you get the answer you want.

Link to comment
Share on other sites

Ok....

I want a PHP that will check if some code exists in HTML code of some website.

Let's say i want to check Example.com...

I need a PHP code in wich I will write some HTML code(let's say: <h1>website</h1>), and in that PHP code i will write website wich I want to check(in this case: Example.com), and that PHP code will look in Example.com website, and tell me if <h1>website</h1> code exists in their HTML....

Link to comment
Share on other sites

First you will have to fetch the contents of the website in quesion. You can do this using something like cURL or file_get_contents. You can then use the examples given. In it's most basic form...

 

$url = 'http://www.google.com';
$search = '<h1>bob</h1>';
$html = file_get_contents($url);

if(strpos($html, $search) !== FALSE) {
echo 'Found';
}

 

Faux Edit: premiso beat me to it, but figured I'd post anyway as I had a basic example.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.