Jump to content

sungo

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sungo's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey guys, I'm new to PHP and am trying to teach myself out of books / off tutorial websites, and I've run into a problem with something I am trying to make. I'm basically trying to make a translation widget that you can enter data into and it will feed that data through a web-based translator (on a different site), parse the data, and feed it back to you. I made a form, that passes the information to the server via cURL and parses the data via regex(/preg_match_all). Sometimes, when you search, there are too many words and you get a "More results" button. I can also grab this data from the server but I cannot seem to make the script parse the web data you get from hitting the button. It merely just loads the host servers website and doesn't re-parse the data. If I added more preg_match_all/regex things, I could strip away the things I want but then it would have to be infinitely deep code for however many pages deep the "More results" goes with the code in the current form. I figure there's a way around this? I'm sure you can do something with a function, to make this work correctly but I'm new so I'm failing hard. I've tried a million different things. If anyone can give me some tips, it'd be much appreciated. I could use the instruction. Thanks! You can check out a the form here My apologizes ahead of time for ugly scripting, but here it is thusfar : <?php // Site is in Japanese EUC encoding, so need a meta content-type echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-JP\" />"; // Establish a form for the possible "More Results" later echo "<FORM NAME=\"inp\" ID=\"inp\" ACTION=\"process2.php\" METHOD=\"POST\" >"; // Parsing POST data variables from the form $dsrchkey = $_POST["dsrchkey"]; $dicsel = $_POST["dicsel"]; $dsrchtype = $_POST["dsrchtype"]; $engpri = $_POST["engpri"]; $exactm = $_POST["exactm"]; $firstkanj = $_POST["firstkanj"]; // Perparing POST variables for cURL if ($dsrchtype=="J") { $dsrchtype_on="&dsrchtype=$dsrchtype"; } else { $dsrchtype_on=""; } if ($engpri=="X") { $engpri_on="&engpri=$engpri"; } else { $engpri_on=""; } if ($exactm=="X") { $exactm_on="&exactm=$exactm"; } else { $exactm_on=""; } if ($firstkanj=="X") { $firstkanj_on="&firstkanj=$firstkanj"; } else { $firstkanj=""; } // cURL for grabbing the data $post_data = "dsrchkey=$dsrchkey&dicsel=$dicsel".$dsrchtype_on.$engpri_on.$exactm_on.$firstkanj; $post = $post_data $url = "http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1E"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $page = curl_exec($ch); // if you click the "More Results" button below, cURL the data from a new url if (isset($_POST['Action'])) { $actionparam = $_POST['actionparam']; $post_data = "actionparam=".$actionparam; $url = "http://www.csse.monash.edu.au/~jwb/cgi-bin/wwwjdic.cgi?1F"; $post = $post_data; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); echo curl_exec($ch); } else { } // Regex to grab appropriate data preg_match_all('/<p>(.+?)<input type="hidden" name="actionparam" value="/s', $page, $match1); // Grabs the variable used to point to "More Results" preg_match_all('/<input type="hidden" name="actionparam" value="(.+?)">/s', $page, $match2); // Checks to see if there are "More results" preg_match_all('/<INPUT TYPE="submit" NAME="Action" VALUE="More(.+?)">/s', $page, $match3); $match_no = $match2[1][0]; $more_match = $match3[1][0]; // Echos Regex'd data echo $match1[1][0]; // If more results exist, make a button to go to the more results! if ( $more_match == "" ) { } else { echo "<input type=\"hidden\" name=\"actionparam\" value=\"".$match_no."\">"; echo "<INPUT TYPE=\"submit\" NAME=\"Action\" VALUE=\"More results\">"; } echo "</form>"; ?> Ideally I'd like to make the script self-contained, meaning it all runs from one php, or two, but I really have limited experience with how to integrate like that. Thanks again!!
  2. Haha. Ok. Thanks. I'll check that out. Appriciate the input.
  3. It's cross server. So I'd be running the script on my server to POST to the other server to grab the data. Any ideas?
  4. Hey guys, kinda new to PHP here. I am trying to play around with retrieving data from a website via CGI. I can do this with the HTML POST form: <FORM ACTION="/cgi-bin/kashi.cgi" METHOD="POST"> <INPUT NAME="file_no" value="29638"> <INPUT NAME="idkdk" value="klflg;fl"> <INPUT type="submit" value="Send"> </FORM> Is there any way to automate this with PHP so I don't have to press a submit button and it just auto load the data?
  5. Hi there, I am wondering about searching through a websites content and snipping such things as news out to be displayed on my website. I'm someone new to php so I looked around for some scripts to tinker with. The only one I could find was: [code] <?php $url = 'http://txt.lyricz.info/test.cgi/rip/dan.txt'; $lines_array = file($url); $lines_string = implode('', $lines_array); eregi("<pre>(.*)</pre>", $lines_string, $head); $lines = split("\n", $head[0]); $x = count($lines); for ($i=0;$i<$x;$i++) {   echo $lines[$i];   echo "\n";   } ?> [/code] As far as I can see all this does is look at the source of $url and clip out the stuff in between < pre> and < /pre>. The one problem with this is that < pre> and < /pre> are still included in the snippit. Also I cannot seem to get this code to work for other variations other then html tags (ie: < pre>, < center>, < head>;, < body>, etc.). I was wondering if there was a better way to go about searching through a websites content and snipping out a bit of info to be displayed elsewhere? Ideally I would like to be able to snip between things such as, " ?sn= " and " '); " Thanks in advance!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.