dc2007 Posted October 11, 2007 Share Posted October 11, 2007 hi what i need is for my script that i have made to be modified into ajax so what ever url is posted in the forms top box it grabbs the info from that site and returns it without the need to submit. heres my code so far Try This URL: http://www.gamestop.com/product.asp?product%5Fid=200362 <form method='POST' name="testForm"> Url:<br /> <input type='text' size='40' name='url' /><br /> <br /><br /> Title:<br /> <input type='text' size='40' id='txtTitle' value='' /><br /> Description:<br /> <textarea id='txtDesc' rows='6' cols='55'></textarea><br /> Image Link:<br /> <input type='text' size='40' id='txtImage' value='' /><br /> <br /><br /> <input type='submit' value='Parse' /> </form> <?php if (isset($_POST['url'])){ $content = get_page($_POST['url']); if (preg_match("~imdb.com~", $_POST['url'])){ preg_match("~<div id=\"tn15title\">.+?<h1>(.+?) <span>~s",$content,$res); $title = $res[1]; preg_match("~<a name=\"poster\"[^>]+><img.+?src=\"([^\"]+)\"~s",$content,$resimg); $image = $resimg[1]; $content1 = get_page($_POST['url']."plotsummary"); preg_match("~<p class=\"plotpar\">(.+?)<i>~s",$content1,$resdesc); $replacements = "/\'/"; $description = addslashes(preg_replace($replacements,'',$resdesc[1])); $description = trim($description); $trailers = $_POST['url']."trailers"; //$description = strip_tags(addslashes($resdesc[1])); print "<script language='JavaScript' type='text/javascript'>testForm.txtTitle.value = '".$title ."';</script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtImage.value = '".$image ."';</script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtDesc.value = '" .$description ."';</script>"; //print "<textarea id='txtDesc' name='txtDesc' rows='6' cols='55'>$description</textarea>"; //print "Title: ".$title."<br>".$description."<br><img src=".$image.">".$trailers."<br>"; }elseif(preg_match("~gamestop.com~", $_POST['url'])){ preg_match("~<td width='580' align='left' class='prodtitle'>(.+?)</td>~s", $content, $res); $titl = $res[1]; preg_match("~<IMG SRC=\"(/common/images/lbox[^\"]+)~s", $content, $res); $img = $res[1]; preg_match("~<td width='620' class='stdcopy'>(.+?)</td>~s", $content, $resdesc); $replacements = "/\'/"; $desc = addslashes(preg_replace($replacements,'',$resdesc[1])); $desc = trim($desc); print "<script language='JavaScript' type='text/javascript'>testForm.txtTitle.value = '".$titl ."';</script>"; print "<script language='JavaScript' type='text/javascript'> testForm.txtDesc.value = '".$desc."'; </script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtImage.value = 'http://www.gamestop.com".$img."';</script>"; //print "<img src='http://www.gamestop.com".$img."'><br>".$desc." ".$titl." <br>"; }elseif(preg_match("~tvrage.com~", $_POST['url'])){ preg_match("~<h3.+?>(.+?)</h3>~s", $content, $res); $tit2 = addslashes($res[1]); $content2 = get_page("http://images.tvrage.net/"); preg_match("~<img src=\"http://images.tvrage.net/shows/3/([^\"]+)\" border='0'>~s",$content,$res); $img2 = $res[1]; preg_match("~padding-bottom: 2px;'><tr><td><img src=.+? border='0'>(.+?)<br> </td></tr><tr>~s", $content, $res); $replacements = "/\'/"; $description = addslashes(preg_replace($replacements,'',$res[1])); $description = trim($description); print "<script language='JavaScript' type='text/javascript'>testForm.txtDesc.value = '".$description."';</script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtTitle.value = '".$tit2 ."';</script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtImage.value = 'http://images.tvrage.net/shows/3/".$img2."';</script>"; //print "<img src='http://images.tvrage.net/shows/3/".$img2."'>".$tit2."<br>".$desc2; } } function get_page($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $content = curl_exec($ch); return $content; } ?> what it basically does is grabs info from 3 sites well it checks which one is added into the url field and returns info from the site. i need it to do it in real time. Quote Link to comment Share on other sites More sharing options...
dc2007 Posted October 13, 2007 Author Share Posted October 13, 2007 can noone help then this is what needs doing you will need to either convert the PHP to javascript some how, consider submiting the info via ajax and parsing an XML response or submit the file twice, once to process the PHP, once for the actual submit. unfortunately, that's the best option since it offers the most accessibility. simple have the form submit to one page that runs the script, and at the same time configures the new action atribute of the form to the page to do your other stuff. i just cant do it. Quote Link to comment Share on other sites More sharing options...
bobleny Posted October 14, 2007 Share Posted October 14, 2007 I'm lazy and don't feel like messing with it, but I will help you out. This is how I would probably do it........ Allow your users to enter in the info: <form method='POST' name="testForm"> Url:<br /> <input type='text' size='40' name='url' /><br /> <br /><br /> Title:<br /> <input type='text' size='40' id='txtTitle' value='' /><br /> Description:<br /> <textarea id='txtDesc' rows='6' cols='55'></textarea><br /> Image Link:<br /> <input type='text' size='40' id='txtImage' value='' /><br /> <br /><br /> <input type='submit' value='Parse' /> </form> <div id="print"></div> Add some JavaScript: <script language="JavaScript" type="text/javascript"> <!-- var GetServer function Connect() { try { // Firefox, Opera 8.0+, Safari GetServer = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { GetServer = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { GetServer = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { return false; } } } } function Check() { return false; Connect(); GetServer.onreadystatechange=function() { if(GetServer.readyState == 4) { document.getElementById("print").innerHTML = GetServer.responseText; } } var url = testForm.url.value; var txtTitle = testform.txtTitle.value; var txtDesc = testform.txtDesc.value; GetServer.open("GET","check.php?url="+url+"&txtTitle="+txtTitle+"&txtDesc="+txtDesc, true); GetServer.send(null); } --> </script> <form onsubmit='return Check(this)' method='POST' name="testForm"> Url:<br /> <input type='text' size='40' name='url' /><br /> <br /><br /> Title:<br /> <input type='text' size='40' id='txtTitle' value='' /><br /> Description:<br /> <textarea id='txtDesc' rows='6' cols='55'></textarea><br /> Image Link:<br /> <input type='text' size='40' id='txtImage' value='' /><br /> <br /><br /> <input type='submit' value='Parse' /> </form> <div id="print"></div> Next you will have to make a new page. Name it, "check.php": <?php if (isset($_GET['url'])){ $content = get_page($_GET['url']); if (preg_match("~imdb.com~", $_GET['url'])){ preg_match("~<div id=\"tn15title\">.+?<h1>(.+?) <span>~s",$content,$res); $title = $res[1]; preg_match("~<a name=\"poster\"[^>]+><img.+?src=\"([^\"]+)\"~s",$content,$resimg); $image = $resimg[1]; $content1 = get_page($_GET['url']."plotsummary"); preg_match("~<p class=\"plotpar\">(.+?)<i>~s",$content1,$resdesc); $replacements = "/\'/"; $description = addslashes(preg_replace($replacements,'',$resdesc[1])); $description = trim($description); $trailers = $_GET['url']."trailers"; //$description = strip_tags(addslashes($resdesc[1])); print "<script language='JavaScript' type='text/javascript'>testForm.txtTitle.value = '".$title ."';</script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtImage.value = '".$image ."';</script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtDesc.value = '" .$description ."';</script>"; //print "<textarea id='txtDesc' name='txtDesc' rows='6' cols='55'>$description</textarea>"; //print "Title: ".$title."<br>".$description."<br><img src=".$image.">".$trailers."<br>"; }elseif(preg_match("~gamestop.com~", $_GET['url'])){ preg_match("~<td width='580' align='left' class='prodtitle'>(.+?)</td>~s", $content, $res); $titl = $res[1]; preg_match("~<IMG SRC=\"(/common/images/lbox[^\"]+)~s", $content, $res); $img = $res[1]; preg_match("~<td width='620' class='stdcopy'>(.+?)</td>~s", $content, $resdesc); $replacements = "/\'/"; $desc = addslashes(preg_replace($replacements,'',$resdesc[1])); $desc = trim($desc); print "<script language='JavaScript' type='text/javascript'>testForm.txtTitle.value = '".$titl ."';</script>"; print "<script language='JavaScript' type='text/javascript'> testForm.txtDesc.value = '".$desc."'; </script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtImage.value = 'http://www.gamestop.com".$img."';</script>"; //print "<img src='http://www.gamestop.com".$img."'><br>".$desc." ".$titl." <br>"; }elseif(preg_match("~tvrage.com~", $_GET['url'])){ preg_match("~<h3.+?>(.+?)</h3>~s", $content, $res); $tit2 = addslashes($res[1]); $content2 = get_page("http://images.tvrage.net/"); preg_match("~<img src=\"http://images.tvrage.net/shows/3/([^\"]+)\" border='0'>~s",$content,$res); $img2 = $res[1]; preg_match("~padding-bottom: 2px;'><tr><td><img src=.+? border='0'>(.+?)<br> </td></tr><tr>~s", $content, $res); $replacements = "/\'/"; $description = addslashes(preg_replace($replacements,'',$res[1])); $description = trim($description); print "<script language='JavaScript' type='text/javascript'>testForm.txtDesc.value = '".$description."';</script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtTitle.value = '".$tit2 ."';</script>"; print "<script language='JavaScript' type='text/javascript'>testForm.txtImage.value = 'http://images.tvrage.net/shows/3/".$img2."';</script>"; //print "<img src='http://images.tvrage.net/shows/3/".$img2."'>".$tit2."<br>".$desc2; } } function get_page($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $content = curl_exec($ch); return $content; } ?> You might have to play with it a bit, but if you need any more help, please ask! Good luck! 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.