PHP search - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Closed Thread
 
Thread Tools Display Modes
 
Old 10-15-2003, 04:52 PM   #1 (permalink)
ADZ
Master Techie
 
Join Date: May 2003
Posts: 2,231
Send a message via Yahoo to ADZ
Default PHP search

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!
__________________

ADZ is offline  
Old 10-15-2003, 11:33 PM   #2 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,364
Send a message via AIM to shan
Default

post the script
__________________

__________________
<center><h2><font color=\"red\">C:\\ Is the root of all evil</font></h2>
<hr width=\"50%\">
phiber@sysdum.com
spam this account, it's fun.
shan is offline  
Old 10-16-2003, 12:07 AM   #3 (permalink)
ADZ
Master Techie
 
Join Date: May 2003
Posts: 2,231
Send a message via Yahoo to ADZ
Default

<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
ADZ is offline  
Old 10-17-2003, 12:39 AM   #4 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,364
Send a message via AIM to shan
Default

PHP Code:
<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)
__________________
<center><h2><font color=\"red\">C:\\ Is the root of all evil</font></h2>
<hr width=\"50%\">
phiber@sysdum.com
spam this account, it's fun.
shan is offline  
Old 10-17-2003, 06:20 PM   #5 (permalink)
ADZ
Master Techie
 
Join Date: May 2003
Posts: 2,231
Send a message via Yahoo to ADZ
Default

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>
ADZ is offline  
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 03:05 PM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.