PHP search

Status
Not open for further replies.

ADZ

Fully Optimized
Messages
2,231
Hi guys,

I am looking for a way to perform a search inside of a html file. I have a huge articles page and want to be able to type in something and it to pull to part of that page...I have been looking online for ways to do that, and have found a script...i can post it up if needs be...but i am a complete noob with php and was hoping to better my knowledge of PHP...anyone got any ideas...im open to them and am gratefull!!!

Thanks

Adam!
 
<style type="text/css">
<!--
a:link {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
a:visited {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
a:hover {
font-family: Verdana;
color: #0000FF;
text-decoration: none;
font-size: 10px;
background-color: #CCCCCC;
}
a:active {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
.unnamed1 {
font-family: Verdana;
font-size: 12px;
color: #000000;
text-decoration: none;
}
-->
</style>
<form method=post>
<table width="236" height="112">
<td align=left colspan="2" height="1"> <p align="center">
<input type=hidden name=dosearch value=yes>
<font face=verdana size=1>Search forte issues by:
<tr>
<td align=left height="1"><font face=verdana size=1>Search key</font>
<td align=left height="1"> <input type=text name=key size="23" style="font:10px verdana; font-weight:bold;">
</tr>
<tr>
<td align=left height="1">
<td align=left height="1"> <input type=hidden name=dosearch value=yes style="font:10px verdana; font-weight:bold;">
<input type=submit value=Search! style="font:10px verdana; font-weight:bold;">
</tr>
</table>
</form>
<?

if($dosearch == "yes")
{

$search_str = $HTTP_POST_VARS['key'];

$fp = file("search.php");

$r = 0;

foreach($fp as $v){
$v = ereg_replace("#", " --- ", $v);

if( stristr($v, $search_str) ){
echo "<font size=2 color=#FF0000>Your Forte Query [ $search_str ] was found </font><hr>";
echo "<font size=2>$v</font>
";
$r++;
}

}

if($r == 0){
print "
<font size=2 color=#FF0000>no result</font><hr>";
}
}
?>








THIS IS FOR SEARCH.PHP
 
PHP:
<style type="text/css">
<!--
a:link {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
a:visited {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
a:hover {
font-family: Verdana;
color: #0000FF;
text-decoration: none;
font-size: 10px;
background-color: #CCCCCC;
}
a:active {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
.unnamed1 {
font-family: Verdana;
font-size: 12px;
color: #000000;
text-decoration: none;
}
-->
</style>
<form method=post>
<table width="236" height="112">
<td align=left colspan="2" height="1"> <p align="center">
<input type=hidden name=dosearch value=yes>
[b]<font face=verdana size=1>Search forte issues by:[/b]
<tr>
<td align=left height="1"><font face=verdana size=1>Search key</font>
<td align=left height="1"> <input type=text name=key size="23" style="font:10px verdana; font-weight:bold;">
</tr>
<tr>
<td align=left height="1">
<td align=left height="1"> <input type=hidden name=dosearch value=yes style="font:10px verdana; font-weight:bold;">
<input type=submit value=Search! style="font:10px verdana; font-weight:bold;">
</tr>
</table>
</form>
<?

if($dosearch == "yes")
{

$search_str = $HTTP_POST_VARS['key'];

$fp = file("search.php");

$r = 0;

foreach($fp as $v){
$v = ereg_replace("#", " --- ", $v);

if( stristr($v, $search_str) ){
echo "<font size=2 color=#FF0000>Your Forte Query [ $search_str ] was found </font><hr>";
echo "<font size=2>$v</font>
";
$r++;
}

}

if($r == 0){
print "
<font size=2 color=#FF0000>no result</font><hr>";
}
}
?>

(for my reference)
 
Supposing i wanted to link the searched entry to the piece of text on the page, how is that accomplished?

For example...i searched 'cow' and it gave me the listings for 'cow' could i click on cow, and it take me to the section of text about the cow?

Cheers

================================

<style type="text/css">
<!--
a:link {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
a:visited {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
a:hover {
font-family: Verdana;
color: #0000FF;
text-decoration: none;
font-size: 10px;
background-color: #CCCCCC;
}
a:active {
font-family: Verdana;
color: #000000;
text-decoration: none;
font-size: 10px;
}
.unnamed1 {
font-family: Verdana;
font-size: 12px;
color: #000000;
text-decoration: none;
}
-->
</style>
<form method=post>
<table width="236" height="112">
<td align=left colspan="2" height="1"> <p align="center">
<input type=hidden name=dosearch value=yes>
<font face=verdana size=1>Search farm yard animal: <tr>
<td align=left height="1"><font face=verdana size=1>Search key</font>
<td align=left height="1"> <input type=text name=key size="23" style="font:10px verdana; font-weight:bold;">
</tr>
<tr>
<td align=left height="1">
<td align=left height="1"> <input type=hidden name=dosearch value=yes style="font:10px verdana; font-weight:bold;">
<input type=submit value=Search! style="font:10px verdana; font-weight:bold;">
</tr>
</table>
</form>
<?

if($dosearch == "yes")
{

$search_str = $HTTP_POST_VARS['key'];

$fp = file("search.php");

$r = 0;

foreach($fp as $v){
$v = ereg_replace("#", " --- ", $v);

if( stristr($v, $search_str) ){
echo "<font size=2 color=#FF0000>Your Forte Query [ $search_str ] was found </font><hr>";
echo "<font size=2>$v</font>
";
$r++;
}

}

if($r == 0){
print "
<font size=2 color=#FF0000>no result</font><hr>";
}
}
?>


</p>


</p>
<p class="unnamed1">I like Ponies...they are pretty...that is why i like them</p>
<p class="unnamed1">Horses are too big...</p>
<p class="unnamed1">Pigs smell ucky</p>
<p class="unnamed1">ducks go quack</p>
<p class="unnamed1">cows go mooooooooo</p>
<p class="unnamed1">chickens taste nice</p>
<p class="unnamed1">Roosters are too damn loud!</p>
<p class="unnamed1">cats go meow</p>
<p class="unnamed1">dogs go woof </p>
<p class="unnamed1"></p>
<p class="unnamed1">I forget other farm animals...although there are plenty more!</p>


</p>
 
Status
Not open for further replies.
Back
Top Bottom