Jump to content

Simple if(strpos question


djtozz

Recommended Posts

I'm trying to undertsand a simple "strpos" sample, but I'm not able to make this work.

 

<?php

$website = "http://www.zshare.net/download/664558148eb3f5z1/";

if(strpos($website,"Downloading")===true){ //check if page contains the word downloading

echo 'Good link<br >'; 

}

else {

echo 'Expired link<br >'; 

}

?>

 

 

Sample links:

 

Working link: http://www.zshare.net/download/664558148eb3f5d1/

 

Expired link: http://www.zshare.net/download/7759897667114c3e/

 

Am I missing something here, or is there an alternative way to do this?

 

Thank you!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/176809-simple-ifstrpos-question/
Share on other sites

I don't know if this will work but I got it from: http://us2.php.net/function.strpos

 

<?php

$website = "http://www.zshare.net/download/664558148eb3f5z1/";
$findme   = "Downloading";
$pos = strpos($website, $findme);


if ($pos === false) {
   echo "Expired link<br >";
} else {
   echo "Good link<br >"; 
}
?>

 

 

Am I missing something here, or is there an alternative way to do this?

Are you wanting to see if the HTML content of the web page http://www.zshare.net/download/664558148eb3f5z1/ contains the word Downloading, or if the string "http://www.zshare.net/download/664558148eb3f5z1/" contains the word downloading?

Thanks for your reaction,

Yes, I just want to see if the html content contains that word, if so then the link is Ok.

In that case, you need to retrieve the content of the page, using either curl, or file_get_contents();

$website = "http://www.zshare.net/download/664558148eb3f5z1/";

$content = file_get_contents($website);

$findme   = "Downloading";
$pos = strpos($content, $findme);


if ($pos === false) {
   echo "Expired link<br >";
} else {
   echo "Good link<br >";
}

Note that you may not have permission to access urls using file_get_contents();

In that case, you need to retrieve the content of the page, using either curl, or file_get_contents();

 

Thank you Mark, your code is working now for rapidshare, megaupload and probably all others.

 

However Zshare seems to be very tricky:

When clicking a bad link: http://www.zshare.net/download/664558148eb3f5d2/ (you get error 404)

 

But I think they're using some kind of redirect for the 404, because If I check the same url with your code and echo the $content I do see the file info:

http://siana.be/search/cron/test.php  while there is nothing to download.

 

so $findme  = "Downloading"; won't work here

 

I think I need something like following

"If page gets redirected to http://www.zshare.net/file-404.html then print bad link"

 

But I really don't have a clue how to solve this.

Any help should be apriciated!

 

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

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