Jump to content

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!'
}

I am wondering, is it possible to get HTML elements with PHP....

Let's say, that some page has this HTML code:

<h1>This is my website</h1>.

Is it possible, that PHP check if that line exists in HTML code?

 

You can use

 

substr_count(string,substring,start,length)

 

Check http://www.w3schools.com/PHP/php_ref_string.asp

 

 

 

 

 

As AlexWD says using strpos would certainly be good enough if you simply wish to test for the string. If however you plan on doing any 'proper' scraping you'd probably be better off with something like domdocument or simplexml rather than Regular Expressions (or possibly a combination of the two).

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?

 

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.

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....

You will need to first grab the contents of the website, curl or file_get_contents will be your primary source to figure that out.

 

Second use the method Alex provided to search the retrieved string data for that string you want and viola, you have it.

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.

 

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.