PHP Problem – counter doesn’t increment
-
Ok, I don’t think I’m a complete gimp, but I’m proly a partial one.
I know this isn’t a WP-specific issue, but I’m putting this here because I know we have some talented PHP’ers out there.
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. I’m trying to do this as a plugin. 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:
$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 this because I pring out the variable in the ID attribute, and it’s 0 everytime. 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
- The topic ‘PHP Problem – counter doesn’t increment’ is closed to new replies.