GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Apr-2003, 00:15
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough

[class] 404 search function code


This was found at
http://nslog.com/archives/2003/02/26/404_search_function_code.php and is said to be for open domain usage and alteration.

PHP Code:

<?php

// NAME: 404 search
// VERSION: n/a
// AUTHOR: Erik J. Barzeski
// WEBSITE: http://nslog.com/
// DESCRIPTION: A function to replace the 404 with a search page 
// particularly for blogs with the search term included e.g. 
// http://nslog.com/blah .  Wrap this up in a 404.php file and set 
// your .htaccess file to read "ErrorDocument 404 /404.php" or 
// something.

$search_term = substr($REQUEST_URI,1);
/**NEED TO CHANGE
  *the REQUEST_URI is the string after the .com so if I have 
  *www.vinayvenkatesh.com/blog/search
  *then this would be "/blog/search" so by saying 6, 
  *I cut out the first 6 characters of that string "/blog/" and set
  *the term I'm searching for to "search".
*/
$search_term = stripslashes($search_term);
$search_url = 'http://blah.com/mt/mt-search.cgi?IncludeBlogs=1&search=';
/**NEED TO CHANGE
  *the url which points to your mt-search.cgi (or whatever search
  * function you use if it isn't Moveable type
*/
$full_search_url = $search_url . $search_term;
$full_page = implode("", file($full_search_url));

$search_string = '/<h3 class="title"><a href="([^"]*)"/';
/**this line picks out the url.  the <h3.. bit was added in 
  *because "Search Results" is a link as well
*/
$count = preg_match_all($search_string, $full_page, $matches); 
// gets the number of results after matching all of the stuff on the page
if(1 == $count)
    header("Location: {$matches[1][0]}");
/** this line autoforwards if there is only one match!
*/
else
    echo $full_page;
/**or shows the search results if there is more than one.
*/
?>


For a site without MT a post commented this.
One remark to the value $search_string:
it matched nothing at me, only if the <, > and " are escaped. Then it worked
Could I have some input into this. Cheers.
Last edited by jrobbio : 22-Apr-2003 at 00:31.
  #2  
Old 22-Apr-2003, 04:42
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Where's the class?


Did you forget something? Where's the class?
  #3  
Old 22-Apr-2003, 04:52
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
Please bare in mind that I don't know what I'm talking about when it comes to PHP still. Could you make the adjustments? Or have I missed out a huge chunk?
  #4  
Old 22-Apr-2003, 05:28
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
That's alright Rob, I just thought that you had missed copying part of the script.

In PHP, a CLASS would look a bit like this:

PHP Code:

<?php
class Whatever
{

  var $who, $what, $where;
  var $how = array();

  function Whatever()
  {
    // some more code...
  }

  function do_something()
  {
    // guess what? even more code...
  }
}
?>

  #5  
Old 22-Apr-2003, 05:50
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
Thanks JDS more sticks every time. What did you think of the script by the way?
  #6  
Old 22-Apr-2003, 05:53
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
To be honest, I haven't tried to figure it out yet... I will reply here when I do that.
  #7  
Old 22-Apr-2003, 09:32
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
The best example is php.net. That's where the original idea came from.
Try http://nslog.com/spider. The MT search function is a bit poo since it shows the first sentnce rather than the keyword you are looking for. Works in some instances I suppose.
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
i/o: set value x (long) before it is used by a function gmn C Programming Language 1 18-Nov-2003 01:12
Search Engine Positioning 101 and 201 "How To" Tips... 000 Search Engine Optimization Forum 0 29-May-2003 10:34
How to search a huge text file for data? JdS MySQL / PHP Forum 7 27-May-2003 09:27
[class] Timer JdS PHP Code Library 2 29-Apr-2003 12:20
[class] Generate Forms Without Using HTML! Elmseeker PHP Code Library 6 11-Mar-2003 12:05

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:56.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.