• User Newbie

    funzione cerca parola in codice php

    Ciao a tutti, ho un problema e spero che qualcuno possa darmi una mano.

    Avevo bisogno di una funzione simile al ctr+f di firefox da inserire nella mia pagina web...mi spiego meglio...una funzione cerca, per trovare una precisa parola nella pagina...
    il problema è che non è una semplice pagina html ma c'è anche del codice php, infatti avevo trovato qualcosa che poteva fare al caso mio ma la parte in php non la trova.

    Questo è quello che avevo trovato
    [HTML]<iframe id="srchform2" src="javascript:'<html><body style=margin:0px; ><form action='javascript:void();' onSubmit=if(this.t1.value!='')parent.findString(this.t1.value);return(false); ><input type=text id=t1 name=t1 value=text size=20><input type=submit name=b1 value=Cerca></form></body></html>'" width=220 height=34 border=0 frameborder=0 scrolling=no> </iframe> <script language="JavaScript"> <!-- var TRange=null; function findString (str) { if (parseInt(navigator.appVersion)<4) return; var strFound; if (window.find) { // CODE FOR BROWSERS THAT SUPPORT window.find strFound=self.find(str); if (!strFound) { strFound=self.find(str,0,1); while (self.find(str,0,1)) continue; } } else if (navigator.appName.indexOf("Microsoft")!=-1) { // EXPLORER-SPECIFIC CODE if (TRange!=null) { TRange.collapse(false); strFound=TRange.findText(str); if (strFound) TRange.select(); } if (TRange==null || strFound==0) { TRange=self.document.body.createTextRange(); strFound=TRange.findText(str); if (strFound) TRange.select(); } } else if (navigator.appName=="Opera") { alert ("Opera browsers not supported, sorry...") return; } if (!strFound) alert ("String '"+str+"' not found!") return; } //--> </script>[/HTML]

    Grazie in anticipo..


  • User Attivo

    La funzione CTRL+F di Firefox serve per trovare parole nel sorgente della pagina. La F sta per Find, verbo trovare in inglese. Il sorgente della pagina non include il tuo PHP che hai lato server, ecco perché l'acronimo di PHP si legge HPP, Hypertext Pre-Processor, perché il sorgente lo elabora PRIMA di mandarlo al browser. L'unica cosa che puoi trovare con una funzione javascript (quello che hai postato è javascript non PHP) è il sorgente restituito al browser, in quanto quest'ultimo il PHP non sa neanche cosa sia.

    Saluti.