Current location: Hot Scripts Forums » Programming Languages » PHP » help : string replace %s output


help : string replace %s output

Reply
  #1 (permalink)  
Old 10-18-03, 07:22 PM
sona sona is offline
New Member
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
help : string replace %s output

this may be asking for too much but still ....

in the main folder mydomain.com, the folder foruma/fr3/messages contains some numbered.php files ( eg 1000.php, 1001.php so on )

i wanted to add a search function so that a word submitted for search can be found out from these files.
however for this files to get displayed in browser they need url like

/foruma/fr3/index.php?subject=view&msg=1001.php
[ http://localhost/foruma/fr3/index.ph...w&msg=1001.php ]

*instead of*

/foruma/fr3/messages/4209.php
http://localhost/foruma/fr3/messages/4209.php

The search function which I got from php cookbook will return results like
/foruma/fr3/messages/1001.php
/foruma/fr3/messages/1002.php
/foruma/fr3/messages/1003.php

but *what i need* is
results ( taking those numbers only )
/foruma/fr3/index.php?subject=view&msg=1001.php
/foruma/fr3/index.php?subject=view&msg=1002.php
/foruma/fr3/index.php?subject=view&msg=1003.php

i am failing miserably - what will be the actual tweaking in the code - i will be full of extreme gratitude if that help is possible.


---------------
the search code
---------------
PHP Code:

<?

function pc_search_dir($dir) { 
global 
$body_regex,$title_regex,$seen;
$pages = array();
$dirs = array();
$seen[realpath($dir)] = true;
if (
is_readable($dir) && ($d dir($dir))) {
while (
false !== ($f $d->read())) {
$path $d->path.'/'.$f;
if (
is_file($path) && is_readable($path)) {
$realpath realpath($path);
if (
$seen[$realpath]) {
continue;
} else {
$seen[$realpath] = true;
}
$file join('',file($path));
if (
preg_match($body_regex,$file)) {
$uri substr_replace($path,'',0,strlen($_SERVER['DOCUMENT_ROOT']));
if (
preg_match('#<title>(.*?)</title>#Sis',$file,$match)) {
array_push($pages,array($uri,$match[1]));
} else {
array_push($pages,array($uri,$uri));
}
}
} else {
if (
is_dir($path) && ('.' != $f) && ('..' != $f)) {
array_push($dirs,$path);
}
}
}
$d->close();
}
foreach (
$dirs as $subdir) {
$realdir realpath($subdir);
if (! 
$seen[$realdir]) {
$seen[$realdir] = true;
$pages array_merge($pages,pc_search_dir($subdir));
}
}
return 
$pages;
}
function 
pc_page_sort($a,$b) {
if (
$a[1] == $b[1]) {
return 
strcmp($a[0],$b[0]);
} else {
return (
$a[1] > $b[1]);
}
}
$matching_pages = array();
$seen = array();
$search_dirs = array('foruma/fr3/messages');
$body_regex '#name(.*' preg_quote(search_item,'#'). 
              
'.*)displayreply#Sis';

foreach (
$search_dirs as $dir) {
$matching_pages array_merge($matching_pages,
                                  
pc_search_dir($_SERVER['DOCUMENT_ROOT'].'/'.$dir));}
if (
count($matching_pages)) {
usort($matching_pages,'pc_page_sort');
print 
'<ul>';
foreach (
$matching_pages as $k => $v) {
print 
sprintf('<li> <a href="%s">%s</a>',$v[0],$v[1]);
}
print 
'</ul>';
} else {
print 
'No pages found.';
}
?>

foruma/fr3/messages = where the searching is done
search_item = the term submittable via a search form

%s = this thing needs to be modified so that only the number is taken and the urls are reconstructed as , for example,
/foruma/fr3/index.php?subject=view&msg=4194.php
[http://localhost//foruma/fr3/index.p...&msg=4194.php]

Once again , thanks a lot for reading this.

Regards
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 07:11 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.