View Full Version : [PHP] Reading files
jw06
February 28th, 2005, 12:24 PM
Hello, I was wondering if anybody knew of a way that I can get certain things out of a text file. What I would be reading was a website, and get the HREF tags out of it. Any ideas?
If I'm not clear let me know.
Thanks
amitgeorge
February 28th, 2005, 01:55 PM
well you have to first open up the html content using fopen and read the entire content using fread. then parse the content using preg_match
if you search you might just find a peice of code with this functionality already
good luck
jw06
February 28th, 2005, 04:43 PM
Is it possible to use preg_match in order to strip out anything with the HREF tags though? All I'm looking to get is the link inside of those tags.
binime
March 1st, 2005, 01:31 AM
Is it possible to use preg_match in order to strip out anything with the HREF tags though? All I'm looking to get is the link inside of those tags.
i just did some playing around with file_get_contents and preg_match
<?php
$content = file_get_contents("test.htm");
if(preg_match("/(?<!<a href=\")(http+(s)?:\/\/[^<>\s]+)/i", $content)) {
echo $content;
}
?>
just change the file in the file_get_contents
jw06
March 1st, 2005, 02:10 PM
Thanks!
binime
March 1st, 2005, 03:11 PM
Thanks!
no probs :D
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.