Would this be feasible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rage
Forum Newbie
Posts: 2
Joined: Wed May 01, 2002 10:21 am

Would this be feasible?

Post by rage »

I have a question. I am a n00b to PHP, but I was wondering how feasible a script like this would be.

Basically, it would search a specific HTML document (preferably the source of the HTML document), and it would look for certain variables. Upon finding those variables, it would select certain HTML off of a page, and then put it in a predetermined place on your website.

Let me give an example incase I am not being very clear.

On my website, I want to be able to post links to new "ACT NOW!" articles found on ACLU's website (http://www.aclu.org/congress/issues107.html). All links to "ACT NOW!" articles, when viewing the source for the webpage posted are proceeded by the list command "li" (not sure if it would convert the "<" and ">" tags to html, so using quotes). They are also the only links on that page using that list command.

I would like to take those and insert it into a location on my webpage (like a side border).

Furthermore, I would like to restrict it to only new postings. Whenever they add a new post to that page, they add a "new!" graphic directly to the right of the link, so we have something (based again upon the HTML source) that can be used to limit that.

Is a script like this feasible? What does the difficulty level look like? Again, I am knew to PHP (I have yet to install it on my computer - I have been looking over tutorials on that and the PHP language for a while...but I am about ready to take that step, and start practicing what I am learning!), so if anyone could point me in the general direction of all of what would be involved in that script, or if there is a script somewhere that does something similar to that so I could look at it and get some idea of what I will need to do, or possibly even use that, then I would greatly appreciate it!
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Post by samscripts »

Yes, it is possible: heres some example code which you can see in action here.

Code: Select all

<?php

$url = "http://www.aclu.org/congress/issues107.html";		// url to grab
$urlstart = "http://www.aclu.org";

$fp = fopen($url,"r");		// open url as a file

if( $fp )&#123;

	$buffer = "";

	// read the html page into a string

	while( !feof($fp) )&#123;
		$buffer .= fgets($fp, 1024);
	&#125;
	fclose($fp);

	// do a regex search and store the results

	$match = '|<li><a href="(&#1111;^"]*)">&#1111; ]*(&#1111;^<]*)&#1111; ]*</a>&#1111; ]*(</li>)?&#1111; ]*<img|is';

	preg_match_all($match, $buffer, $links);

	// get the http address of the site and convert any relative links to absolute ones

	for( $i = 0; $i < count($links&#1111;1]); $i++)&#123;
		$link = $links&#1111;1]&#1111;$i];
		if( !preg_match('|^http|i', $link) )&#123;
			$link = $urlstart.str_replace('//','/','/'.$link);
		&#125;

		// display the link

		echo '<a href="'.$link.'">'.$links&#1111;2]&#1111;$i].'</a><br>';
	&#125;

&#125;
?>
good luck with php,

sam
rage
Forum Newbie
Posts: 2
Joined: Wed May 01, 2002 10:21 am

Post by rage »

wow.... :D

thanks for the fast reply..that is awsome...

Now to pour over the code, and figure out the certain parts I don't understand ;)
Post Reply