Current location: Hot Scripts Forums » Programming Languages » PHP » matching extension with what exists.


matching extension with what exists.

Reply
  #1 (permalink)  
Old 12-21-05, 12:07 AM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
matching extension with what exists.

Been a while, but when in doubt ask the ppl here. LOL

Here's the problem...

Converting an existing script from 1 column content to 3 column content. For script purposes I've used l, r and m to represent left, right and middle. My old script would have had this same problem, but I never used extensions for content other than html. Now that I'm using plain text content also (for ease of updating) a portion of this script is failing.

Basically, if it matches an extension further down in the list of extensions in the array and then it matches an extension further up in the array it's not setting the extension to what it should.

I'll paste the code and hopefully it will make some since...

sry for the documentation in it also. I tend to loose track of things if I don't document them.

PHP Code:

//----=[Extension Array]=--------------------------------------------------


$extension[] = "html";      ///////////////////////////////////////////////////////
$extension[] = "htm";       //  This is the extention array. It is used to define
$extension[] = "php";       //  what extensions are valid. If you need to use an
$extension[] = "txt";       //  extension not listed just add another line in the 
//$extension[] = "inc";     //  same format
//$extension[] = "asp";     ///////////////////////////////////////////////////////
//$extension[] = "js";

///////////////////////////////////////////////////////////////////
//---=[ Extension Verification ]=---------------------------------
//
// Plain and simple it checks to make sure the extension 
// matches the extension of the file that exists, if so it sets
// the extension of $lc_ext, $rc_ext, $mc_ext and $t_ext
//
// $lc_ext is the extension of the left column content file
// $rc_ext is the extension of the right column content file
// $mc_ext is the extension of the middle column content file
// $t_ext is the extension of the template file
//
///////////////////////////////////////////////////////////////////

$exttest "nomatch";

for (
$i=0;$i<count($extension);$i++)

{
    if(
$exttest == "nomatch"
    {
        if(
file_exists($lfile'.' .$extension[$i])) 
        {
            
$lc_ext $extension[$i];
            
$exttest "matchone";
        }
    } 
        if(
$exttest == "matchone")
    {
        if(
file_exists($rfile'.' .$extension[$i])) 
        {
            
$rc_ext $extension[$i];
            
$exttest "matchtwo";
        }
    } 
// start matchine
    
        
if($exttest == "matchtwo")
    {
        if(
file_exists($mfile'.' .$extension[$i]))
        {
            
$mc_ext $extension[$i];
            
$exttest "matchthree";
        }
    }
    
    if(
$exttest == "matchthree")
    {
        if(
file_exists($ncstemplate'.' .$extension[$i])) 
        {
            
$t_ext $extension[$i];
            
$exttest "allmatch";
        }

    }
    if(
$exttest == "allmatch")
    {
        break;
    }

If this matches a .txt for the $lc_ext and $rc_ext, but matches .html for $mc_ext and $t_ext then $lc_ext and $rc_ext returns the .txt extension, but the $mc_ext and $t_ext is empty, nothing defined. If all files are .html, then all is good.

It's like if it matches an extension further down in the array first, then finds one with html at the top of the array then it won't return the .html for those. It's driving me nuts!

Anyway, this is probably long enuf.

RJ

(Afterthought to original post)
Should I use separate "for" statements for each file and extension that needs matched up? I would think it would work with one instead of 4. would become very tedius and long if I decided to go with 5 or 10 dynamic content areas on a single page where some load up as html and some load up as text and some load up as php.

Last edited by rjwebgraphix; 12-21-05 at 12:23 AM.
Reply With Quote
  #2 (permalink)  
Old 12-21-05, 02:14 PM
rjwebgraphix rjwebgraphix is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
I separated them into multiple loops, one for each file extension I want to look for and this works. Do you see a way of simplifying it? Escpecially if you would want to add more areas of dynamic content on a single page?

PHP Code:

// --=[ Checks extension of the Left column content file and sets lc_ext to that ext ]=--

$exttest "nomatch";

for (
$i=0;$i<count($extension);$i++)

{
    if(
$exttest == "nomatch"// start matching
    
{
        if(
file_exists($lfile'.' .$extension[$i])) // Match Left File with Extension
        
{
            
$lc_ext $extension[$i];
            
$exttest "matchone";
        }
    } 
    if(
$exttest == "matchone")
    {
        break;
    }
}

// --=[ Checks extension of the Right column content file and sets rc_ext to that ext ]=--
$exttest "nomatch";

for (
$i=0;$i<count($extension);$i++)

{
    if(
$exttest == "nomatch")
    {
        if(
file_exists($rfile'.' .$extension[$i])) // Match right File with Extension
        
{
            
$rc_ext $extension[$i];
            
$exttest "matchtwo";
        }
    }
    if(
$exttest == "matchtwo")
    {
        break;
    }
}

// --=[ Checks extension of the middle column content file and sets mc_ext to that ext ]=--
$exttest "nomatch";

for (
$i=0;$i<count($extension);$i++)

{    
    if(
$exttest == "nomatch")
    {
        if(
file_exists($mfile'.' .$extension[$i])) // Match Middle File with Extension
        
{
            
$mc_ext $extension[$i];
            
$exttest "matchthree";
        }
    }
    if(
$exttest == "matchthree")
    {
        break;
    }
}

// --=[ Checks extension of the template file and sets t_ext to that ext ]=--    
$exttest "nomatch";

for (
$i=0;$i<count($extension);$i++)

{
    if(
$exttest == "nomatch")
    {
        if(
file_exists($ncstemplate'.' .$extension[$i])) // Match template with extension
        
{
            
$t_ext $extension[$i];
            
$exttest "matchfour";
        }

    }
    if(
$exttest == "matchfour")
    {
        break;
    }

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
php files with no extension? liljoeyjordison PHP 4 09-03-05 01:46 PM
[SOLVED] check if directory exists lordy PHP 2 07-04-05 01:17 AM
How to intsall extension? weilies PHP 1 05-18-05 12:19 AM
how do i check to see if something already exists in a column in a DB tisza PHP 2 01-06-04 06:54 PM
Tar Backup of selected file extension dhiru The Lounge 0 12-26-03 06:12 AM


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