embed. en php. page html maintien. extension html help!

  • ukshopsnet
  • Novice
  • Novice
  • No Avatar
  • Inscription: Aoû 03, 2003
  • Messages: 21
  • Loc: HIGH PEAK, UK
  • Status: Offline

Message Avril 27th, 2004, 3:35 pm

Salut

Couple de questions:

1. Essayant d'obtenir une modification sur le code ci-dessous, afin que je puisse afficher n'importe quelle recherche prédéfinie qui me plaît, par exemple, pour ma page des finances, je peut avoir des résultats sur la page pour le mot clé «prêts». Je veux que la boîte de recherche pour être encore utilisable pour toute autre recherche, le visiteur choisit. De cette façon je peux créer un bon nombre de recherches prédéfinies et obtenir les pages keyworded et entièrement optimisé - et faites beaucoup d'intérêt des moteurs de recherche dans ces pages.

2. Je veux intégrer le XML. Feed PHP dans une page html et de conserver l'extension. Html - de cette façon je peux utiliser des pages existantes avec des annonces de bonnes moteur de recherche pour afficher le flux - est-ce possible ???????


Mirago XML Parser Code Source (mon ID utilisateur est omis dans le code)

Code: [ Select ]


--------------------------------------------------------------------------------

<?php

function status($message) {
 return "onMouseOver=\"window.status='$message'; return true;\" onMouseOut=\"window.status=''; return true;\"";
}

function displayResult($resultid, $title, $abstract, $redir, $url) {
 global $offset, $webtag;
 $statusbar = status("visit: $url");
 If (substr($redir,0,65)<>substr($url,0,65)) {
  If ($resultid==1) {
  echo "<b>Featured Sites</b>";
  $webtag=0;
  }
 } else {
  If ($webtag<>1) {
  echo "<b>Web Results</b>";
  $webtag = 1;
  }
 }
 echo "<DL>\n<DT><A $statusbar HREF=\"$redir\"><b>".($offset + $resultid).". $title</b></a></DT>";
 echo "<DD>$abstract</DD>\n<DD>$url</DD>\n</DL>\n";
}

// handles the attributes for opening tags
// $attrs is a multidimensional array keyed by attribute
// name and having the value of that attribute
function startElement($parser, $name, $attrs=''){
 global $currenttag, $parenttag, $title, $abstract, $redir, $url, $resultset, $resultid;
 if ($currenttag == "") { $parenttag = $currenttag; }
$currenttag = $name;
 if (count($attrs) > 0) {

 foreach($attrs as $keys) {
//   print ($keys);
  if ($name == "RESULTSET") {
   $resultset = $attrs;
  }
  if ($name == "RESULT") {
   $resultid = $attrs["ID"]+1;
   //print ($attrs["ID"]);
  }
  }
 }
}

// $current_tag lets us know what tag we are currently
// dealing with - we use that later in the characterData
// function.
function endElement($parser, $name, $attrs=''){
 global $currenttag, $parenttag, $title, $abstract, $redir, $url, $resultset, $resultid;
 global $Atitle, $Aabstract, $Aredir, $Aurl;

 if ($name == "RESULT") {
 //displayResult($resultid, $title, $abstract, $redir, $url);
  array_push($Atitle, $title);
  array_push($Aabstract, $abstract);
  array_push($Aredir, $redir);
  array_push($Aurl, $url);
  $title = "";
  $abstract = "";
  $redir = "";
  $url = "";
 }
 $currenttag = "";
}

// this function is passed data between elements
function characterData($parser, $data){
 global $currenttag, $parenttag, $title, $abstract, $redir, $url, $resultset, $resultid, $alttxt;
 //$data =~ s/£/£/;
 if (($currenttag == "ALT") && ($data != "\n")) { $alttxt = $data; }
 if (($currenttag == "TITLE") && ($data != "\n")) { $title = $title . $data; }
 if (($currenttag == "ABSTRACT") && ($data != "\n")) { $abstract = $abstract . $data; }
 if (($currenttag == "URL") && ($data != "\n")) { $url = $url . $data; }
 if (($currenttag == "REDIR") && ($data != "\n")) { $redir = $redir . $data; }
}

global $qry, $nres, $nfs, $offset, $details;
global $ass, $fsonly, $ns, $hl, $alt, $alttxt;
global $querykey, $queryvar;
foreach($_REQUEST As $querykey => $queryvar) {
 eval("$$querykey = \"$queryvar\";");
}

$qry = stripslashes($qry);

$nres == 0 ? $nres = 10 : 0;
$nfs == "" ? $nfs = 3 : 0;
$offset == "" ? $offset = 0: 0;
$details == "" ? $details = 1 : 0;
$fsonly == "" ? $fsonly = 0: 0;
$hl == "" ? $hl = 0: 0;
$alt == "" ? $alt = 0: 0;

// $ns == "" ? $ns = 0: 0;


$Atitle = array();
$Aabstract = array();
$Aredir = array();
$Aurl = array();

$xml_feed = "http://www.mirago.co.uk/scripts/xmlhandler.aspx?";
$xml_feed .= "&qry="   . urlencode($qry);
$xml_feed .= "&ass="   . $ass;
$xml_feed .= "&details=". $details;
$xml_feed .= "&nres="  . $nres;
$xml_feed .= "&offset=" . $offset;
$xml_feed .= "&nfs=" . $nfs;
$xml_feed .= "&fsonly=" . $fsonly;
$xml_feed .= "&hl=" . $hl;
$xml_feed .= "&ns=" . $ns;
$xml_feed .= "&alt=" . $alt;

$pagelink = getenv("SCRIPT_NAME") . "?qry=" . urlencode($qry) . "&ass=$ass&nres=$nres&details=$details&fsonly=$fsonly&hl=$hl&nfs=$nfs&ns=$ns&alt=$alt";

// what are we parsing?
$type = 'ISO-8859-1';

// create our parser
$xml_parser = xml_parser_create($type);

// set some parser options
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, $type);

// this tells PHP what functions to call when it finds an element
// these funcitons also handle the element's attributes
xml_set_element_handler($xml_parser, 'startElement','endElement');

// this tells PHP what function to use on the character data
xml_set_character_data_handler($xml_parser, 'characterData');

if (!($fp = fopen($xml_feed, 'r'))) {
die("Could not open $xml_feed for parsing!\n");
}

// loop through the file and parse baby!
while ($data = fread ($fp, 4096)) {
// if (!($data = utf8_encode($data))) {
// echo 'ERROR'."\n";
// }
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf( "XML error: %s at line %d\n\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);



?>

<html>
 <head>
  <title>Mirago XML PHP Example</title>
  <STYLE>
DT {
 font-family:Tahoma;
 font-size:12px;
 font-weight:bold;
}
DD {
 font-family:Tahoma;
 font-size:12px;
 font-weight:normal;
}
P {
 font-family:Tahoma;
 font-size:12px;
 font-weight:normal;
}
input {font-family:Tahoma; font-size:11px;}
  </STYLE>
 </head>
<body>
<h1 style="font-family:Tahoma;font-size:18px;font-weight:bold">Mirago Search Results</h1>
<p style="font-family:Tahoma;font-size:12px;">
<form name="xmlsearch" action=<? echo '"' . getenv('SCRIPT_NAME') . '"' ?> method="GET">
<input type="hidden" name="ass" value="1000">
<input type="text" name="qry" size=25 style="font-size:12px" value=<? echo '"'.htmlspecialchars($qry).'"' ?>>
<input type="submit" name="cmdSearch" value="Search" style="font-family:Verdana;font-size:12px;"><br>
&nbsp;
<b>Options</b>
<div style="font-family:Tahoma;font-size:12px">
<input type="checkbox" name="details" value="1"<? if ($details == 1) { echo " checked"; } ?>> Show Details
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="fsonly" value="1"<? if ($fsonly == "1") { echo " checked"; } ?>> Featured Sites Only<br>
<input type="checkbox" name="hl" value="1"<? if ($hl == "1") { echo " checked"; } ?>> Highlight Search Terms<br>
<input type="checkbox" name="ns" value="1"<? if ($ns == "1") { echo " checked"; } ?>> Precise Match Featured Sites<br>
<input type="checkbox" name="alt" value="1"<? if ($alt == "1") { echo " checked"; } ?>> Alternate Search Terms<br>
<input type="text" name="nfs" size=1 maxlength=2 value=<?echo "\"$nfs\"" ?>> No of Featured Sites to Display<br>
<input type="text" name="nres" size=1 maxlength=2 value=<?echo "\"$nres\"" ?>> No of Results to Display<br>
&nbsp;
</div></form>
<p style="font-size:14px;">
<?
 if ($qry != "") echo "You searched for <b>". htmlspecialchars($qry) . "</b> : ";
 if ($resultset["NUMRESULTS"] != 0) {
  echo "Showing Results " . ($offset+1) . " - " . ($offset + $resultset["NUMRESULTS"]);
 } else {
  If ($qry<>"") {echo "No results were returned";}
 }
echo "<br><hr size=1>";

// This outputs the alternate search terms
if ($alttxt != "") {
  global $altterms;
  $altterms = explode(", ",$alttxt);
echo "<br><b>Also Try The Following Searches:</b><br>";
foreach ($altterms as $alttxt) {
if ($altterms[0] != $alttxt) { echo", ";}
echo "<a href=?qry=".urlencode($alttxt).">".$alttxt."</a>";
}
echo "<br><br>";
}

for ($i = 1; $i <= $resultset["NUMRESULTS"]; $i++) {
 $title = array_shift($Atitle);
 $abstract = array_shift($Aabstract);
 $redir = array_shift($Aredir);
 $url = array_shift($Aurl);
 displayResult($i, $title, $abstract, $redir, $url);
}


if (($resultset["MORERESULTS"] == "True") || ($offset < "0")) {
  echo "<p align=right style=font-size:14px;font-family:Verdana>";
  if ($offset != "0") { echo "<a " . status("Previous $nres Results") . " href=\"$pagelink&offset=" . ($offset-$nres) ."\"><b><< Previous results</b></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; }
  if (($resultset["MORERESULTS"] == "True") && ($offset < (200 - $nres))) { echo "<a ". status("Next $nres Results") . " href=\"$pagelink&offset=" . ($offset+$nres) ."\"><b>More results >></b></a>"; }
}

?>
<hr size=1>
<p align=center>&copy; 2003 Mirago PLC</p>
</body>
</html>
  1. --------------------------------------------------------------------------------
  2. <?php
  3. function status($message) {
  4.  return "onMouseOver=\"window.status='$message'; return true;\" onMouseOut=\"window.status=''; return true;\"";
  5. }
  6. function displayResult($resultid, $title, $abstract, $redir, $url) {
  7.  global $offset, $webtag;
  8.  $statusbar = status("visit: $url");
  9.  If (substr($redir,0,65)<>substr($url,0,65)) {
  10.   If ($resultid==1) {
  11.   echo "<b>Featured Sites</b>";
  12.   $webtag=0;
  13.   }
  14.  } else {
  15.   If ($webtag<>1) {
  16.   echo "<b>Web Results</b>";
  17.   $webtag = 1;
  18.   }
  19.  }
  20.  echo "<DL>\n<DT><A $statusbar HREF=\"$redir\"><b>".($offset + $resultid).". $title</b></a></DT>";
  21.  echo "<DD>$abstract</DD>\n<DD>$url</DD>\n</DL>\n";
  22. }
  23. // handles the attributes for opening tags
  24. // $attrs is a multidimensional array keyed by attribute
  25. // name and having the value of that attribute
  26. function startElement($parser, $name, $attrs=''){
  27.  global $currenttag, $parenttag, $title, $abstract, $redir, $url, $resultset, $resultid;
  28.  if ($currenttag == "") { $parenttag = $currenttag; }
  29. $currenttag = $name;
  30.  if (count($attrs) > 0) {
  31.  foreach($attrs as $keys) {
  32. //   print ($keys);
  33.   if ($name == "RESULTSET") {
  34.    $resultset = $attrs;
  35.   }
  36.   if ($name == "RESULT") {
  37.    $resultid = $attrs["ID"]+1;
  38.    //print ($attrs["ID"]);
  39.   }
  40.   }
  41.  }
  42. }
  43. // $current_tag lets us know what tag we are currently
  44. // dealing with - we use that later in the characterData
  45. // function.
  46. function endElement($parser, $name, $attrs=''){
  47.  global $currenttag, $parenttag, $title, $abstract, $redir, $url, $resultset, $resultid;
  48.  global $Atitle, $Aabstract, $Aredir, $Aurl;
  49.  if ($name == "RESULT") {
  50.  //displayResult($resultid, $title, $abstract, $redir, $url);
  51.   array_push($Atitle, $title);
  52.   array_push($Aabstract, $abstract);
  53.   array_push($Aredir, $redir);
  54.   array_push($Aurl, $url);
  55.   $title = "";
  56.   $abstract = "";
  57.   $redir = "";
  58.   $url = "";
  59.  }
  60.  $currenttag = "";
  61. }
  62. // this function is passed data between elements
  63. function characterData($parser, $data){
  64.  global $currenttag, $parenttag, $title, $abstract, $redir, $url, $resultset, $resultid, $alttxt;
  65.  //$data =~ s/£/£/;
  66.  if (($currenttag == "ALT") && ($data != "\n")) { $alttxt = $data; }
  67.  if (($currenttag == "TITLE") && ($data != "\n")) { $title = $title . $data; }
  68.  if (($currenttag == "ABSTRACT") && ($data != "\n")) { $abstract = $abstract . $data; }
  69.  if (($currenttag == "URL") && ($data != "\n")) { $url = $url . $data; }
  70.  if (($currenttag == "REDIR") && ($data != "\n")) { $redir = $redir . $data; }
  71. }
  72. global $qry, $nres, $nfs, $offset, $details;
  73. global $ass, $fsonly, $ns, $hl, $alt, $alttxt;
  74. global $querykey, $queryvar;
  75. foreach($_REQUEST As $querykey => $queryvar) {
  76.  eval("$$querykey = \"$queryvar\";");
  77. }
  78. $qry = stripslashes($qry);
  79. $nres == 0 ? $nres = 10 : 0;
  80. $nfs == "" ? $nfs = 3 : 0;
  81. $offset == "" ? $offset = 0: 0;
  82. $details == "" ? $details = 1 : 0;
  83. $fsonly == "" ? $fsonly = 0: 0;
  84. $hl == "" ? $hl = 0: 0;
  85. $alt == "" ? $alt = 0: 0;
  86. // $ns == "" ? $ns = 0: 0;
  87. $Atitle = array();
  88. $Aabstract = array();
  89. $Aredir = array();
  90. $Aurl = array();
  91. $xml_feed = "http://www.mirago.co.uk/scripts/xmlhandler.aspx?";
  92. $xml_feed .= "&qry="   . urlencode($qry);
  93. $xml_feed .= "&ass="   . $ass;
  94. $xml_feed .= "&details=". $details;
  95. $xml_feed .= "&nres="  . $nres;
  96. $xml_feed .= "&offset=" . $offset;
  97. $xml_feed .= "&nfs=" . $nfs;
  98. $xml_feed .= "&fsonly=" . $fsonly;
  99. $xml_feed .= "&hl=" . $hl;
  100. $xml_feed .= "&ns=" . $ns;
  101. $xml_feed .= "&alt=" . $alt;
  102. $pagelink = getenv("SCRIPT_NAME") . "?qry=" . urlencode($qry) . "&ass=$ass&nres=$nres&details=$details&fsonly=$fsonly&hl=$hl&nfs=$nfs&ns=$ns&alt=$alt";
  103. // what are we parsing?
  104. $type = 'ISO-8859-1';
  105. // create our parser
  106. $xml_parser = xml_parser_create($type);
  107. // set some parser options
  108. xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
  109. xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, $type);
  110. // this tells PHP what functions to call when it finds an element
  111. // these funcitons also handle the element's attributes
  112. xml_set_element_handler($xml_parser, 'startElement','endElement');
  113. // this tells PHP what function to use on the character data
  114. xml_set_character_data_handler($xml_parser, 'characterData');
  115. if (!($fp = fopen($xml_feed, 'r'))) {
  116. die("Could not open $xml_feed for parsing!\n");
  117. }
  118. // loop through the file and parse baby!
  119. while ($data = fread ($fp, 4096)) {
  120. // if (!($data = utf8_encode($data))) {
  121. // echo 'ERROR'."\n";
  122. // }
  123. if (!xml_parse($xml_parser, $data, feof($fp))) {
  124. die(sprintf( "XML error: %s at line %d\n\n",
  125. xml_error_string(xml_get_error_code($xml_parser)),
  126. xml_get_current_line_number($xml_parser)));
  127. }
  128. }
  129. xml_parser_free($xml_parser);
  130. ?>
  131. <html>
  132.  <head>
  133.   <title>Mirago XML PHP Example</title>
  134.   <STYLE>
  135. DT {
  136.  font-family:Tahoma;
  137.  font-size:12px;
  138.  font-weight:bold;
  139. }
  140. DD {
  141.  font-family:Tahoma;
  142.  font-size:12px;
  143.  font-weight:normal;
  144. }
  145. P {
  146.  font-family:Tahoma;
  147.  font-size:12px;
  148.  font-weight:normal;
  149. }
  150. input {font-family:Tahoma; font-size:11px;}
  151.   </STYLE>
  152.  </head>
  153. <body>
  154. <h1 style="font-family:Tahoma;font-size:18px;font-weight:bold">Mirago Search Results</h1>
  155. <p style="font-family:Tahoma;font-size:12px;">
  156. <form name="xmlsearch" action=<? echo '"' . getenv('SCRIPT_NAME') . '"' ?> method="GET">
  157. <input type="hidden" name="ass" value="1000">
  158. <input type="text" name="qry" size=25 style="font-size:12px" value=<? echo '"'.htmlspecialchars($qry).'"' ?>>
  159. <input type="submit" name="cmdSearch" value="Search" style="font-family:Verdana;font-size:12px;"><br>
  160. &nbsp;
  161. <b>Options</b>
  162. <div style="font-family:Tahoma;font-size:12px">
  163. <input type="checkbox" name="details" value="1"<? if ($details == 1) { echo " checked"; } ?>> Show Details
  164. &nbsp;&nbsp;&nbsp;&nbsp;
  165. <input type="checkbox" name="fsonly" value="1"<? if ($fsonly == "1") { echo " checked"; } ?>> Featured Sites Only<br>
  166. <input type="checkbox" name="hl" value="1"<? if ($hl == "1") { echo " checked"; } ?>> Highlight Search Terms<br>
  167. <input type="checkbox" name="ns" value="1"<? if ($ns == "1") { echo " checked"; } ?>> Precise Match Featured Sites<br>
  168. <input type="checkbox" name="alt" value="1"<? if ($alt == "1") { echo " checked"; } ?>> Alternate Search Terms<br>
  169. <input type="text" name="nfs" size=1 maxlength=2 value=<?echo "\"$nfs\"" ?>> No of Featured Sites to Display<br>
  170. <input type="text" name="nres" size=1 maxlength=2 value=<?echo "\"$nres\"" ?>> No of Results to Display<br>
  171. &nbsp;
  172. </div></form>
  173. <p style="font-size:14px;">
  174. <?
  175.  if ($qry != "") echo "You searched for <b>". htmlspecialchars($qry) . "</b> : ";
  176.  if ($resultset["NUMRESULTS"] != 0) {
  177.   echo "Showing Results " . ($offset+1) . " - " . ($offset + $resultset["NUMRESULTS"]);
  178.  } else {
  179.   If ($qry<>"") {echo "No results were returned";}
  180.  }
  181. echo "<br><hr size=1>";
  182. // This outputs the alternate search terms
  183. if ($alttxt != "") {
  184.   global $altterms;
  185.   $altterms = explode(", ",$alttxt);
  186. echo "<br><b>Also Try The Following Searches:</b><br>";
  187. foreach ($altterms as $alttxt) {
  188. if ($altterms[0] != $alttxt) { echo", ";}
  189. echo "<a href=?qry=".urlencode($alttxt).">".$alttxt."</a>";
  190. }
  191. echo "<br><br>";
  192. }
  193. for ($i = 1; $i <= $resultset["NUMRESULTS"]; $i++) {
  194.  $title = array_shift($Atitle);
  195.  $abstract = array_shift($Aabstract);
  196.  $redir = array_shift($Aredir);
  197.  $url = array_shift($Aurl);
  198.  displayResult($i, $title, $abstract, $redir, $url);
  199. }
  200. if (($resultset["MORERESULTS"] == "True") || ($offset < "0")) {
  201.   echo "<p align=right style=font-size:14px;font-family:Verdana>";
  202.   if ($offset != "0") { echo "<a " . status("Previous $nres Results") . " href=\"$pagelink&offset=" . ($offset-$nres) ."\"><b><< Previous results</b></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; }
  203.   if (($resultset["MORERESULTS"] == "True") && ($offset < (200 - $nres))) { echo "<a ". status("Next $nres Results") . " href=\"$pagelink&offset=" . ($offset+$nres) ."\"><b>More results >></b></a>"; }
  204. }
  205. ?>
  206. <hr size=1>
  207. <p align=center>&copy; 2003 Mirago PLC</p>
  208. </body>
  209. </html>
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Avril 27th, 2004, 3:35 pm

  • Managedlinks
  • Proficient
  • Proficient
  • No Avatar
  • Inscription: Mar 31, 2004
  • Messages: 294
  • Status: Offline

Message Avril 28th, 2004, 6:58 pm

Cette page vous montre comment faire des pages html, php, comme le travail

http://www.managedlinks.com/htaccess.html

Afficher de l'information

  • Total des messages de ce sujet: 2 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 139 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC