1bigbear Posted October 17, 2009 Share Posted October 17, 2009 Hi I have a file that contains a list of links in text, like this http://www.phpfreaks.com/forums/11 http://www.phpfreaks.com/forums/1555 without the x The page source code looks like this <link>http://www.phpfreaks.com/forums/11</link><br/> <link>http://www.phpfreaks.com/forums/1</link><br/> I want to parse the text and send each link to another script, but I don't know how to do this, could you help me. Quote Link to comment Share on other sites More sharing options...
cags Posted October 17, 2009 Share Posted October 17, 2009 If the file your reading looks like this... <link>http://www.phpfreaks.com/forums/11</link><br/> <link>http://www.phpfreaks.com/forums/1</link><br/> ... then you could use something like... $input = file_get_contents($path); preg_match_all("~<link>(.*)?</link>~", $input, $output); // the links you then want are stored in $output[1] as an array. Quote Link to comment Share on other sites More sharing options...
1bigbear Posted October 17, 2009 Author Share Posted October 17, 2009 If I ad echo $output[1]; to show what did he get $input = file_get_contents($path); preg_match_all("~<link>(.*)?</link>~", $input, $output); // the links you then want are stored in $output[1] as an array. echo $output[1]; I get this result Array Quote Link to comment Share on other sites More sharing options...
cags Posted October 17, 2009 Share Posted October 17, 2009 Yes, you would, as I said... // the links you then want are stored in $output[1] as an array. print_r($output[1]); Quote Link to comment Share on other sites More sharing options...
1bigbear Posted October 17, 2009 Author Share Posted October 17, 2009 I cant get it to work now it show Array ( ) Quote Link to comment Share on other sites More sharing options...
1bigbear Posted October 17, 2009 Author Share Posted October 17, 2009 It work, it didn't work with a php file but with a html file it work, it show before the first link this Array ( [0] => Quote Link to comment Share on other sites More sharing options...
1bigbear Posted October 17, 2009 Author Share Posted October 17, 2009 the links are stored in one array, if I send them to a database will they get put together or each link will get a separate place. I want to compare the links to other from the database Quote Link to comment Share on other sites More sharing options...
cags Posted October 17, 2009 Share Posted October 17, 2009 So loop through the array... foreach($output[1] as $URL) { // whatever you wish to do here. } Quote Link to comment Share on other sites More sharing options...
1bigbear Posted October 22, 2009 Author Share Posted October 22, 2009 I have a script that searches for the link in a db but I don't know how to send each link from this script to the one that searches. Any ideas? Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 No, I don't understand what your asking. Why is the search in a seperate script to where you need it, why not just put it in the same script. If there is a reason for it to be in a seperate script then you will need to use either $_SESSION variables to pass information between scripts or depending on the nature of teh scripts use the include function to bring the other scripts functions into scope. Quote Link to comment Share on other sites More sharing options...
1bigbear Posted October 22, 2009 Author Share Posted October 22, 2009 I can put them together but how do I make the search script to take each link and search? Quote Link to comment Share on other sites More sharing options...
cags Posted October 22, 2009 Share Posted October 22, 2009 Er.. So loop through the array... foreach($output[1] as $URL) { // whatever you wish to do here. } Just place your search code in place of the //whatever you wish to do here 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.