Quantcast

Maximum PC

It is currently Mon Apr 21, 2014 12:00 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Dexter's dumb PHP question of the day...
PostPosted: Mon Oct 11, 2004 1:40 pm 
In the lab!
In the lab!
User avatar

Joined: Sun Jun 06, 2004 10:47 am
Posts: 831
Location: Secret Laboratory
ok I have an array with the following values:
"/usr/home/dexter/public_html/images/thumbs/set_1"
"/usr/home/dexter/public_html/images/thumbs"
"/usr/home/dexter/public_html"
"/usr/home/dexter"
"/usr/home"

the question how do i find if one of those entries contains the following string value as a a part of the entry:
"/usr/home/dexter/public_html/images"

but since multiple ones do match I only want to find the one closest to the search value. that is to say I would want to find "/usr/home/dexter/public_html/images/thumbs" is the result of the search.

This should be an easy question that I can solve but I've been coding all day and I'm fried so any help would be great :?


Top
  Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 4:49 pm 
Team Member Top 100
Team Member Top 100

Joined: Fri Sep 17, 2004 5:35 pm
Posts: 1176
Look into the substr() function.


Top
  Profile  
 
 Post subject: Re: Dexter's dumb PHP question of the day...
PostPosted: Mon Oct 11, 2004 11:59 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Dex... In Java I would do the following. Sort the array and then do a binary search using a comparator. This allows you to customize the sort to meet your needs.

I'm not sure if PHP supports comparators, but a regular binary search should either give you an match exact match or put you very close to where you want to be in the array.


Top
  Profile  
 
 Post subject:
PostPosted: Tue Oct 12, 2004 12:02 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Kybo_Ren wrote:
Look into the substr() function.

How does this help? I can think of one or two ways of using it, but none of them seem paticulary promising. :/


Top
  Profile  
 
 Post subject:
PostPosted: Tue Oct 12, 2004 5:29 am 
In the lab!
In the lab!
User avatar

Joined: Sun Jun 06, 2004 10:47 am
Posts: 831
Location: Secret Laboratory
actually my original question didn't explain things exactly correctly. I got it figured out though...

it was easy once I took a break and let my brain relax :)


Top
  Profile  
 
 Post subject:
PostPosted: Tue Oct 12, 2004 9:33 am 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Amazing how much that helps... :)


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group