|
-
Jul 24th, 2004, 09:57 AM
#1
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($newContent, 0, $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.
-
Jul 24th, 2004, 08:14 PM
#2
Turns out I'm an idiot.... I switched variable names part way through.... it's those little things in life... *sigh
TG
-
Jul 26th, 2004, 07:09 AM
#3
Frenzied Member
-
Jul 26th, 2004, 08:20 AM
#4
Originally posted by ober0330
*** is this?? Try:
Does it really matter? 
The result is the same both.
-
Jul 26th, 2004, 08:43 AM
#5
Frenzied Member
No, it doesn't really, but ++ is faster and why would you do +=1 when ++ is available to you? Why reinvent the wheel????
-
Jul 26th, 2004, 09:11 AM
#6
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.
-
Jul 26th, 2004, 09:16 AM
#7
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
-
Jul 26th, 2004, 01:01 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|