Results 1 to 8 of 8

Thread: Counter Not Incrementing - What Gives? [RESOLVED]

  1. #1

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Counter Not Incrementing - What Gives? [RESOLVED]

    Ok, I don't think I'm a complete gimp, but I'm proly a partial one.

    The background: I want to add a dropcase letter to my website, and I only want it on the first letter of each part, not on every paragraph, so using CSS is out of the question. So, what I'm trying to do is as each section is processed, I grab the content (passed in as $content), grab the first letter and change the markup. The problem is that sometimes the first thing is some HTML. So I want to skip over the HTML, find the first displayable letter, pull it out of the HTML, and then prepend it so that the dropcase is then followed by the rest of the content.

    This should give you an idea of what I'm talking about.

    So, here's my code that I am using:
    PHP Code:
    $newContent trim($content);

    $ltrPos 0;
    $openTag '';

    $first_letter substr($newContent,0,1); // Get the first letter

    if ($first_letter == '<') {
    //The text is marked up and we have an opening tag
    //Need to get past that to find the first chr. Should
    // be able to find it by searching for the matching >
        
        
    while ($firstLetter == '<') {
            while(
    substr($newContent,$ltrPos,1) != '>')
                {
                    
    $ltrPos +=1// $ltrPos + 1;
                
    }
            
    $openTag substr($newContent0$ltrPos+1);
           
    $first_letter substr($newContent,$ltrPos+1,0);
        }
        
    $newContent "<div class='drop-case' id='".$ltrPos."'>".$first_letter."</div>".$openTag.substr($newContent,$cnt+2);
    }else {
        
    $newContent "<div class='drop-case'>".$first_letter."</div>".substr($newContent,1);
    }


    return 
    $newContent
    From what I can tell, my $ltrPos isn't being incremented. I can tell that it's going into the top part, where $first_letter == '<' but it doesn't seem to be going through either of the while loops.

    Can any one see what I may have smegged up?

    TG
    Last edited by techgnome; Jul 24th, 2004 at 08:14 PM.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  2. #2

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Turns out I'm an idiot.... I switched variable names part way through.... it's those little things in life... *sigh

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    *** is this??
    PHP Code:
    $ltrPos +=1
    Try:
    PHP Code:
    $ltrPos++; 
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Originally posted by ober0330
    *** is this??
    PHP Code:
    $ltrPos +=1
    Try:
    PHP Code:
    $ltrPos++; 
    Does it really matter?

    The result is the same both.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    No, it doesn't really, but ++ is faster and why would you do +=1 when ++ is available to you? Why reinvent the wheel????
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    I don't see why there would be a speed difference. Both statements are identical and its not reinventing the wheel is mearly using a different method of achieving the same result.

    Maybe tech prefers to use +=1 rather than ++ becuase it makes his code look clearer.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    I prefer += simply because that's what I'm used to from other languages. Coinsidently, ober0330 is right ++ is faster than +=..... read that in several places, although no one could explain why, but I think it has something to do with the way the language was compiled.

    As a side note, I have gone back and updated the code to use ++.... so far I've not noticed any diff, but sometimes every little bit helps.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    In a scripting language like PHP which is never optimized, ++ is likely to be faster because it's more direct, i.e. it's clear that it means "increment by one", unlike += , where an argument needs to be parsed first.
    The difference is minimal though, especially with a free type system like most scripting languages have.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width