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. Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/ 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. Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-938573 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 Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-938581 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]); Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-938582 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 ( ) Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-938585 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] => Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-938587 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 Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-938588 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. } Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-938590 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? Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-941824 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. Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-941826 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? Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-941828 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 Link to comment https://forums.phpfreaks.com/topic/178011-parsing-and-sending-text-separately-to-another-file/#findComment-941838 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.