Need help with PHP code that pulls information from another site's DIV tags

Hi,

I need help with the following code. I’m trying to pull information from another website and display it on my own. The information is within Div tags, and this site updates this information daily. The code i’m trying to use is below, any help is appreciated I haven’t had any luck!

<?php $friendsPage = file_get_contents("http://www.iec-houston.org"); $divStart = strpos($friendsPage, "<div id='salatTime'"); $divEnd = strpos($friendsPage, "", $divStart); $divContents = substr($friendsPage, $divStart, $divEnd - $divStart + 6); ?>

Code looks to be ok, if that’s the only way you can get the data…

Step through it line by line and see what you’re getting.

[php]
$friendsPage = file_get_contents(“http://www.iec-houston.org”);
var_dump($friendsPage); // Are you getting the content?
$divStart = strpos($friendsPage, “<div id=‘salatTime’”);

if ($divStart !== FALSE) {
$divEnd = strpos($friendsPage, “”, $divStart); //Hope the HTML is proper!
$divContents = substr($friendsPage, $divStart, $divEnd - $divStart + 6);
echo $divContents;
} else {
// No start position found
}

[/php]
It would probably be a lot cleaner to use regular expressions in this case (preg_martch w/matches). But you’re on your own on with that, I’m horrible at regex :wink: Maybe someone else can post the pattern?

Nope the content is not coming through. That’s the issue i’m having.

Odd… works on my end:

[php]
$friendsPage = file_get_contents(“http://www.iec-houston.org”);
echo $friendsPage;

//Output:
/*

... */

[/php]

Maybe try using cURL instead. Only thing I can think of is something on that site’s configuration errors on non-browser requests. With cURL you can set a User Agent, etc.

http://www.php.net/manual/en/function.curl-init.php

Shrugs…

were you able to get those timings to show up? Maybe I don’t have the write code placed in the html to call the php. This is what I have…

               	  <p><font color ="Black"><strong>
               	    <script type="text/javascript">
		<!--
			printdate();
		// -->
		          </script></font></strong></p>
				  <script type="text/javascript" src="style/prayertimes.php"></script>

I have the php code placed in the prayertimes.php file. Am I calling the file correctly?

Sponsor our Newsletter | Privacy Policy | Terms of Service