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!
Would this be feasible?
Moderator: General Moderators
-
samscripts
- Forum Commoner
- Posts: 57
- Joined: Tue Apr 23, 2002 4:34 pm
- Location: London, UK
Yes, it is possible: heres some example code which you can see in action here.
good luck with php,
sam
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 ){
$buffer = "";
// read the html page into a string
while( !feof($fp) ){
$buffer .= fgets($fp, 1024);
}
fclose($fp);
// do a regex search and store the results
$match = '|<li><a href="(ї^"]*)">ї ]*(ї^<]*)ї ]*</a>ї ]*(</li>)?ї ]*<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ї1]); $i++){
$link = $linksї1]ї$i];
if( !preg_match('|^http|i', $link) ){
$link = $urlstart.str_replace('//','/','/'.$link);
}
// display the link
echo '<a href="'.$link.'">'.$linksї2]ї$i].'</a><br>';
}
}
?>sam