1

I have a question, is there any way to check a url if contain a word and then show this value? For example I want to check if in the external site exist ver. 1.x.x.x, this value ver. 1.x.x.x never will be the same. I make something like this, but maybe is another solution.

<form enctype="multipart/form-data" action="" method="post">
    <input name="url" type="text"/>
    <input type="submit" name="submit" value="Check" class="btn btn-primary"/><br/>
</form>


<?php
if(isset($_POST['submit'])) {
    $url = $_POST['url'];
}
$content = file_get_contents($url);
$first_step = explode( '<p class="copyright">' , $content );
$second_step = explode("</p>" , $first_step[1] );
echo $second_step[0];
?>

In the external url this is the html container

<p class="copyright">
Help Us -
<a href="http://www.externalsite.com/">
(ver. 1.x.x.x)
<br>
Robert
  • 812
  • 3
  • 18
  • 47

2 Answers2

1

Your question has two parts to it. The first is to request the page, which you can do with a simple curl request. As taken from the php docs here is an example of a curl request.

<?php 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "example.com"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); // $output is the content
curl_close($ch);

The next part is to actually get that value. A fantastic and disgustingly upvoted stack overflow answer has already been done on this and is fairly straight forward to follow.

Community
  • 1
  • 1
Ne Ma
  • 1,719
  • 13
  • 19
  • I understand but to make this with javascript? is not a better solution? – Robert Mar 14 '15 at 10:04
  • Well PHP and JS serve clearly distinct purposes; one being server side(runs on the server) and the other runs on the clients browser. It ultimately depends on where you want the transaction to be occuring. Given your example it would be better to stick with PHP and have the information before the page renders. – Ne Ma Mar 14 '15 at 10:09
  • all this must be on my site, I can't access the client site, so I need to get the url, the url in the client website always will have this /download , and in this /download page I need to find and show in my website that version. – Robert Mar 14 '15 at 10:11
  • It is "all on your site". You make a request for the page content. – Ne Ma Mar 14 '15 at 10:12
  • this need to be like a check script, the customer will enter their website in my input field and I need to check their website version. – Robert Mar 14 '15 at 10:14
  • For the love of.... Right. Copy and paste the code into your site. You already have PHP code on the form... change it. – Ne Ma Mar 14 '15 at 10:15
  • can you update your answer with the correct version of code please? – Robert Mar 14 '15 at 10:25
  • No because my code is not complete and requires you to do more(read the link). – Ne Ma Mar 14 '15 at 20:06
  • I see this thank you but I am not an expert, for that I ask here about this, I found my self that link before... If you want to help me please make that answer complete, thank you again – Robert Mar 15 '15 at 08:15
1

You can use SimpleHTMLDOm or DOMDocument lib in PHP. Or many other libraries :)

SimpleHtmlDom lib

$html = file_get_html($url);
echo $html->find("p[class=copyright]",0)->innertext;

DOMDocument

$doc = new DOMDocument();
$doc->loadHTMLFile($url);

$xml = simplexml_import_dom($doc);

var_dump($xml->xpath('//*[@class="copyright"]'));
Community
  • 1
  • 1