hainhim Posted July 15, 2007 Share Posted July 15, 2007 Hi, everybody!Because i'm not a programer, please help me convert this php.file to aspthis php file at http://www.w3schools.com/php/php_ajax_livesearch.asp<?php$xmlDoc = new DOMDocument();$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL$q=$_GET["q"];//lookup all links from the xml file if length of q>0if (strlen($q) > 0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } else { $hint=$hint . "<br /><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint == "") { $response="no suggestion"; }else { $response=$hint; }//output the responseecho $response;?>when i convert it (at www.me-u.com):<%Dim gv_xmlDoc, gv_x, gv_q, gv__GET(), gv_i, gv_y, gv_z, gv_hint, gv_responsegv_xmlDoc = new DOMDocument()gv_xmlDoc->load("links.xml");gv_x = gv_xmlDoc->getElementsByTagName("link")/get the q parameter from URLgv_q = gv__GET("q")/lookup all links from the xml file if length of q>0If Length ( $q ) > 0 then $hint = "" For gv_i = 0 to (gv_x->length) gv_y = gv_x->item(gv_i)->getElementsByTagName("title") gv_z = gv_x->item(gv_i)->getElementsByTagName("url") If gv_y->item(0)->nodeType==1 then ' find a link matching the search text If stristr(gv_y->item(0)->childNodes->item(0)->nodeValue,gv_q then ) { If gv_hint=="" then gv_hint="<a href=""" . " & z & ""->item(0)->childNodes->item(0)->nodeValue . """ target="_blank">" & $y->item(0)->childNodes->item(0)->nodeValue & "</a>"; End If Else gv_hint = gv_hint & "<br /><a href=""" . " & z & ""->item(0)->childNodes->item(0)->nodeValue . """ target="_blank">" & $y->item(0)->childNodes->item(0)->nodeValue & "</a>" End IfNextEnd If/Set output to "no suggestion"if no hint were found' or to the correct values If $hint == "" then gv_response = "no suggestion" Else $response = $hint End If/output the responseResponse.Write $response %>But it has errors?Help me, please.Thanks. Link to comment Share on other sites More sharing options...
boen_robot Posted July 15, 2007 Share Posted July 15, 2007 The only error I see as a person that does NOT know ASP is that "/" is used for comments. As far as I'm aware, ASP uses apostrophes (') for comments.Try that: <%Dim gv_xmlDoc, gv_x, gv_q, gv__GET(), gv_i, gv_y, gv_z, gv_hint, gv_responsegv_xmlDoc = new DOMDocument()gv_xmlDoc->load("links.xml");gv_x = gv_xmlDoc->getElementsByTagName("link")'get the q parameter from URLgv_q = gv__GET("q")'lookup all links from the xml file if length of q>0If Length ( $q ) > 0 then$hint = ""For gv_i = 0 to (gv_x->length)gv_y = gv_x->item(gv_i)->getElementsByTagName("title")gv_z = gv_x->item(gv_i)->getElementsByTagName("url")If gv_y->item(0)->nodeType==1 then' find a link matching the search textIf stristr(gv_y->item(0)->childNodes->item(0)->nodeValue,gv_q then){If gv_hint=="" thengv_hint="<a href=""" . " & z & ""->item(0)->childNodes->item(0)->nodeValue . """ target="_blank">" & $y->item(0)->childNodes->item(0)->nodeValue & "</a>";End IfElsegv_hint = gv_hint & "<br /><a href=""" . " & z & ""->item(0)->childNodes->item(0)->nodeValue . """ target="_blank">" & $y->item(0)->childNodes->item(0)->nodeValue & "</a>"End IfNextEnd If'Set output to "no suggestion"if no hint were found' or to the correct valuesIf $hint == "" thengv_response = "no suggestion"Else$response = $hintEnd If'output the responseResponse.Write $response%> Link to comment Share on other sites More sharing options...
hainhim Posted July 16, 2007 Author Share Posted July 16, 2007 Thanks very much about your reply.Please help me repair this error:Error Type:Microsoft VBScript compilation (0x800A0401)Expected end of statement/MyWeb/livesearch.asp, line 5, column 27gv_xmlDoc = new DOMDocument()--------------------------^Browser Type:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727) Page:GET /MyWeb/livesearch.aspThanks for help. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 16, 2007 Share Posted July 16, 2007 That converter does not do a very good job. First off, I really doubt that this is going to work:gv_xmlDoc = new DOMDocument()DOMDocument is not a VBScript object, and that's not the syntax to create a new Server or ActiveX object. Also, lines like these:gv_hint = gv_hint & "<br /><a href=""" ." & z & ""->item(0)->childNodes->item(0)->nodeValue .""" target="_blank">" & $y->item(0)->childNodes->item(0)->nodeValue & "</a>"are neither ASP nor PHP. You're not going to be able to just run code through a converter and convert it to another language. Each language has certain libraries and things that it depends on that just don't directly translate from one language to another. Instead of just converting code, you need to understand what the first piece of code is doing, and figure out how to do that same thing in another language. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.