djtozz Posted October 7, 2009 Share Posted October 7, 2009 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! Quote Link to comment Share on other sites More sharing options...
phpretard Posted October 7, 2009 Share Posted October 7, 2009 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 >"; } ?> Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 7, 2009 Share Posted October 7, 2009 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? Quote Link to comment Share on other sites More sharing options...
djtozz Posted October 7, 2009 Author Share Posted October 7, 2009 I don't know if this will work but I got it from: http://us2.php.net/function.strpos Thanks for the feedback, but this doesn't seems to work for me. Quote Link to comment Share on other sites More sharing options...
djtozz Posted October 7, 2009 Author Share Posted October 7, 2009 Are you wanting to see if the HTML content of the web page 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. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 7, 2009 Share Posted October 7, 2009 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(); Quote Link to comment Share on other sites More sharing options...
djtozz Posted October 7, 2009 Author Share Posted October 7, 2009 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.