jp2b81 Posted January 19, 2008 Share Posted January 19, 2008 Ok so I have something I am trying to accomplish and I am not sure if it's possible I am using a lot of different types of coding php, css, flash, html to name a few What I am curious of is if there is a way to create a file that would read another website and lets say for example I wanted a particular part like a certain table's information to be read then created into a .txt file but with variable around it... I'll try to give an example We'll say the website has a section I have thats is coded like <table><tr><td>HEY I'M THE INFORMATION HE WANTS</td></tr></table> is there a way to have create something that will read the site and look for that specific section then take the text and put it in a text file with a variable for flash like &varOne=HEY I'M THE INFORMATION HE WANTS& If further explination is needed just ask I will try wasnt really sure how to explain it the big reason I want this is because I multiple different sites that ultimately have to get updated and its a very long process sometimes some of the information is the same but others isn't so I was hoping to be able to just update the one site and be good to go. I would just make the text file myself but some of the information that I want copied is generated already by other scripts Thanks for your time -Jp2b Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/ Share on other sites More sharing options...
resago Posted January 19, 2008 Share Posted January 19, 2008 yeah Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443806 Share on other sites More sharing options...
jp2b81 Posted January 19, 2008 Author Share Posted January 19, 2008 any resources that you might be able to point me to to accomplish it? i am fine with taking forever for me to figure it out but I have no idea where to start looking lol Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443810 Share on other sites More sharing options...
resago Posted January 20, 2008 Share Posted January 20, 2008 look a uses of the "file" function, php.net is a great place. also look at egrep functions. Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443910 Share on other sites More sharing options...
pkSML Posted January 20, 2008 Share Posted January 20, 2008 You would need to know the exact context of the data you want. You could use preg_match to grab data between <table> and </table>. But what if there is more than one table in the page? Then you'd need preg_match_all() and know which table to grab. PHP is only as smart as you tell it to be. Also, is there a specific format that this data is you're trying to retrieve? That might make things easier. Is this data dynamic? Does it have a specific scheme? ... Any more information will help us help you. Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443919 Share on other sites More sharing options...
revraz Posted January 20, 2008 Share Posted January 20, 2008 Search for CURL Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443920 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Also XML or DOM functions will make it a lot easier to sift through the data if you don't want to wander into the dark and gloomy world of regular expressions. Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443922 Share on other sites More sharing options...
jp2b81 Posted January 20, 2008 Author Share Posted January 20, 2008 I know this might sound strange but the information I am trying to grab is from my space so its all in html or css .... I do know the exact locations of the tables... I am making a design for myself to test but also making a design for a friend who wants to for whatever reason get his page to look like something different. (I think it defeats the point) but hey experience is experience. I don't want to get him a log to my sites just to edit his text field so I am trying to just have him update things there and then be able to just go from there weather it be to an actual website or to his own my space page no matter what will work. Does that help at all? Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443928 Share on other sites More sharing options...
resago Posted January 20, 2008 Share Posted January 20, 2008 $file=file("http://whatever"); may not be correct syntax. since you are the author of the info we want to get, put the data between unique tags, like: <--START_HERE--> <--END_HERE--> if you put them on their own line, you don't need preg stuff, just for ($i=0; $i<count($file); $i++){ if (trim($file[$i])=="<--START_HERE-->"){ $i++; while (trim($file[$i])!="<--END_HERE-->"){ $stuff+=$file[$i]; $i++; } } } $stuff is a string of all your html you wanted to capture. Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443930 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 MySpace has ghastly HTML so I would recommend going the way of regular expressions rather than DOM functions like I suggested earlier. Or... you could stop using MySpace and use a better social networking site like <a href="http://virb.com">Virb</a> Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443934 Share on other sites More sharing options...
jp2b81 Posted January 20, 2008 Author Share Posted January 20, 2008 $file=file("http://whatever"); may not be correct syntax. since you are the author of the info we want to get, put the data between unique tags, like: <--START_HERE--> <--END_HERE--> if you put them on their own line, you don't need preg stuff, just for ($i=0; $i<count($file); $i++){ if (trim($file[$i])=="<--START_HERE-->"){ $i++; while (trim($file[$i])!="<--END_HERE-->"){ $stuff+=$file[$i]; $i++; } } } $stuff is a string of all your html you wanted to capture. Cool that will work for the information you fill out now I just need something for the automated things ... you guys so rock Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443939 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Does MySpace not strip out HTML comment tags? Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443944 Share on other sites More sharing options...
jp2b81 Posted January 20, 2008 Author Share Posted January 20, 2008 Does MySpace not strip out HTML comment tags? No it just ignores them and keeps going Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443947 Share on other sites More sharing options...
resago Posted January 20, 2008 Share Posted January 20, 2008 you might want to check the syntax on my code, I get confused between C++,JS,Java,PHP,Perl, etc... Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443950 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Syntax looks fine although personally I would use foreach. Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443951 Share on other sites More sharing options...
jp2b81 Posted January 20, 2008 Author Share Posted January 20, 2008 $file=file("http://whatever"); may not be correct syntax. since you are the author of the info we want to get, put the data between unique tags, like: <--START_HERE--> <--END_HERE--> if you put them on their own line, you don't need preg stuff, just for ($i=0; $i<count($file); $i++){ if (trim($file[$i])=="<--START_HERE-->"){ $i++; while (trim($file[$i])!="<--END_HERE-->"){ $stuff+=$file[$i]; $i++; } } } $stuff is a string of all your html you wanted to capture. Only thing I am lost on is what to add to the code to get it to write the whatever.txt file ... keep in mind I am still sorta new to php but I have never been one to take it slow into things lol Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443952 Share on other sites More sharing options...
resago Posted January 20, 2008 Share Posted January 20, 2008 $file=file("http://whatever"); # this is input may not be correct syntax. since you are the author of the info we want to get, put the data between unique tags, like: <--START_HERE--> <--END_HERE--> if you put them on their own line, you don't need preg stuff, just $stuff="&varOne="; for ($i=0; $i<count($file); $i++){ if (trim($file[$i])=="<--START_HERE-->"){ $i++; while (trim($file[$i])!="<--END_HERE-->"){ $stuff.=$file[$i]; $i++; } } } $stuff.="&"; fileputcontents($stuff,"yourtextfile.txt"); #this is output again, I'm not looking at the manual, so check the syntax. Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443960 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 file_put_contents() is available only for PHP versions >= 5 so you might have to use: <?php $h = fopen('yourtextfile.txt', 'a'); fwrite($h, $stuff); fclose($h); ?> Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443963 Share on other sites More sharing options...
jp2b81 Posted January 20, 2008 Author Share Posted January 20, 2008 Ok I will try this out and see what happens should I hit the answered thing for now and make a new topic if needed? Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443972 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Well just ask yourself: 'Has my question been answered?'. Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443981 Share on other sites More sharing options...
jp2b81 Posted January 20, 2008 Author Share Posted January 20, 2008 Well just ask yourself: 'Has my question been answered?'. It has for all of the information I have the ability to add the html comment tags to but with the automatic generated things I am confused still ??? I think the biggest reason is I heard quite a few different things that said they should work but if I get something that will read and right for those things that doesnt make my brain hurt then yes it would be answered lol Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443990 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 May I suggest you look <a href="http://www.regular-expressions.info/">here</a>. Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-443995 Share on other sites More sharing options...
jp2b81 Posted January 20, 2008 Author Share Posted January 20, 2008 May I suggest you look <a href="http://www.regular-expressions.info/">here</a>. thanks i am so glad my friends recommended here to learn and tweak my php you guys soooooooooo rock Quote Link to comment https://forums.phpfreaks.com/topic/86840-solved-odd-question-but-this-is-the-best-place-to-ask-those/#findComment-444001 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.