curtm Posted March 13, 2006 Share Posted March 13, 2006 I need help creating a script please.I need a script where I could enter in a url, click submit, and have the script go to that url, look for "<form" and then pull out the method="xxxx" and the action="xxxxxxxxxxxxxxxxx" and all of the input name="xxxxx" and options and selects.Basically, I want an easy way to find out where a form is being submitted to, and all the form valune names.Can anyone help with this?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/4853-need-help-on-a-script/ Share on other sites More sharing options...
redbullmarky Posted March 13, 2006 Share Posted March 13, 2006 [!--quoteo(post=354571:date=Mar 13 2006, 05:19 PM:name=curtm)--][div class=\'quotetop\']QUOTE(curtm @ Mar 13 2006, 05:19 PM) [snapback]354571[/snapback][/div][div class=\'quotemain\'][!--quotec--]I need help creating a script please.I need a script where I could enter in a url, click submit, and have the script go to that url, look for "<form" and then pull out the method="xxxx" and the action="xxxxxxxxxxxxxxxxx" and all of the input name="xxxxx" and options and selects.Basically, I want an easy way to find out where a form is being submitted to, and all the form valune names.Can anyone help with this?Thanks![/quote]you're asking alot in one go. there are a few things you need to look at here:1, opening and reading the contents of a webpage into a variable.2, regular expressions (preg_match, etc) to actually draw out the relevent info from the variable.unless you drop it in the freelance forum, i don't think you're gonna have much luck getting someone to write the whole script for you, as it's not a simple straightforward 'get this, do that' script. give it a blast, then post any code you have when you get into problems and we'd probably be able to help you much more.Cheers Quote Link to comment https://forums.phpfreaks.com/topic/4853-need-help-on-a-script/#findComment-17087 Share on other sites More sharing options...
curtm Posted March 13, 2006 Author Share Posted March 13, 2006 Here is what I have working so far...$sFile = file_get_contents("http://www.domain.com", False);preg_match_all("/(\<[ \\n\\r\\t]{0,}tr[^>]*\>|\<[^>]*[\\n\\r\\t]{1,}tr[^>]*\>){1}([^<]*<([^(\/>)]*(\/[^(t>)]){0,1}(\/t[^(r>)]){0,1})*>)*(\<[ \\n\\r\\t]{0,}\/tr[^>]*\>|\<[^>]*[\\n\\r\\t]{1,}\/tr[^>]*\>){1}/i", $sFile, $matches); foreach ($matches as $val) { echo "matched: " . $val[0] . "\n"; echo "part 1: " . $val[1] . "\n"; echo "part 2: " . $val[3] . "\n"; echo "part 3: " . $val[4] . "\n\n";}The script above prints "matched:" and "part1" .... for every <tr> on domain.com, So I am getting closer,but I don't get the code after preg_match_all - all the <'s and >'s and \'s - how does that stuff work?I think if I can get it to pull out everything between <form and </form> I can get the rest to work.Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/4853-need-help-on-a-script/#findComment-17146 Share on other sites More sharing options...
redbullmarky Posted March 14, 2006 Share Posted March 14, 2006 [!--quoteo(post=354663:date=Mar 13 2006, 09:32 PM:name=curtm)--][div class=\'quotetop\']QUOTE(curtm @ Mar 13 2006, 09:32 PM) [snapback]354663[/snapback][/div][div class=\'quotemain\'][!--quotec--]but I don't get the code after preg_match_all - all the <'s and >'s and \'s - how does that stuff work?[/quote]haha welcome to regular expressions. i still don't fully understand them now, but all the bits you mention are patterns that will match to the information youre after. in the case of the < and </ etc, this is literally trying to match the opening and closing tags in HTML and returns the contents. as regex has certain operators that define the way a pattern is matched, a backslash (\) is used to let the parser know that the following character is literally the character you want to match, and not an operator. just like if you wanted to put an apostrophe in a string, you'd backslash it first to tell the php parser that you really want the apostrophe, and don't mean it to be the closing quote of a string:[code]$nameplural = 'mark's'; // will give an error$nameplural = 'mark\'s'; // is fine[/code][!--quoteo(post=354663:date=Mar 13 2006, 09:32 PM:name=curtm)--][div class=\'quotetop\']QUOTE(curtm @ Mar 13 2006, 09:32 PM) [snapback]354663[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think if I can get it to pull out everything between <form and </form> I can get the rest to work.Thanks![/quote]well, you say that, but all you get left with when you've pulled out the bits between the form tags is a smaller version of the page you started with, which you'll then need to match INPUT and TEXTAREA and BUTTON tags, etc. without looking too heavily into the preg_match pattern you have, it appears youre very much on the right lines.but:[code]$result = preg_match("/\<form\>(.*?)\<\/form\>/i", $sFile, $resultsarray);print_r($resultsarray);[/code]should return all the info between the form tags.i'd personally stick with preg_match_all though and try and work it out. it aint easy, but once you've nailed it you can do some pretty tricky search and replace tasks in minimal amount of code.Hope that helpsCheers Quote Link to comment https://forums.phpfreaks.com/topic/4853-need-help-on-a-script/#findComment-17286 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.