GKWelding Posted October 14, 2008 Share Posted October 14, 2008 Ok, I have a form on another web page that is not private or protected. Basically what I want to do is load the form values that are loaded when you view the webpage into a PHP script on another server and then take those form values and load them into PHP variables. I understand that loading the values into variables is the easy bit, I was just wondering if there are any PHP functions I am missing that allow PHP to load external web pages and preen data from them? Thanks in advance for the help... Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted October 14, 2008 Share Posted October 14, 2008 file_get_contents(); can open files on another server. But it depends on file permissions etc. check in the manual for more info Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 14, 2008 Author Share Posted October 14, 2008 Cheers, This may look like the only solution to my question. I will have to use the file_get_contents(). I guess the best solution for this problem would be to copy the entire completed form into a string generated by file_get_contents() then 'clip' out the bits of information I require. Example code to use for clipping the string once loaded, for those who are interested, is given below. I don't know if this will work yet as I'm not on my machine so don't hold me to this... function strstr_after($haystack, $needle_start, $needle_end) { $pos_start = $strpos($haystack, $needle_start); $pos_end = $strpos($haystack, $needle_end); $length = $pos_end - $pos_start; if (is_int($pos_start) && is_int($pos_end)) { return substr($haystack, $pos_start+1, $length-1)); } return $pos; } // Example $email = 'name@example.com'; $domain = strstr_after($email, '@', '.'); echo $domain; // prints example Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 14, 2008 Share Posted October 14, 2008 You might have an easier time if you use some regular expressions. This tutorial will help you understand a bit about them, though you'll have to wait for the next one (or, of course, google) for something to show you how to apply them to pull out text. Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 14, 2008 Author Share Posted October 14, 2008 So for the example above: $email = 'name@example.com'; preg_match (!e(.+)e!, $email, $domain); print_r($domain); // prints e@example $email = 'name@example.com'; preg_match (!e(.+?)e!, $email, $domain); print_r($domain); // prints e@e Therefore the code below would give me everything between, and including, the input tags. I would have to set up some logic though to strip out every instance of them occuring in the string if they occur more than once though or do regular expressions support this? $formstring = $file_get_string; preg_match (!<input(.+?)input>!, $formstring, $matches); I could then do a replace function on the input tags to leave just the data. Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 14, 2008 Author Share Posted October 14, 2008 Never mind, I just read the regex stuff again and it carries on through the string matching all instances and outputting them to an array under $matches[0], $matches[1]... etc... 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.