NameSilo

Simple while() loop problem... (Ignore all my other topics lol - read this one)

Spaceship Spaceship
Watch

user-7256

VIP Member
Impact
111
Hi,

*** PROBLEM FIXED ***

My 3rd topic... wow this is a record for me in this board... anyways,

I have this code:

PHP:
while (strpos($tutorial, ":code.", $i) > 0)
  {

   //These echo() statements are for my debugging purposes

    //echo($i."<BR>");
    $i = strpos($tutorial, ":code.", $i) + 6;
    //echo($i." ");
    $ii = strpos($tutorial, ":", $i); + 1;
    //echo($ii." ");
    $idnum = substr($tutorial, $i, $ii - $i);
    //echo("~".$idnum."~ ... ");
    
   //************************
   //Thanks, dabb, for pointing the below line of code out. LOL.
    exit;
  }

It's written quickly, so it's not very good ... but...

I want it to go through the entire string, $tutorial, and what it's searching for is this:

:code.1:

And it's trying to take the number out of that sub string. It works GREAT for the first occurance of :code.1:-, but does not continue.

Any help appreciated,

-Matt
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
100 NP$ reward. But it has to work.
 
0
•••
A regex is perfect here. Unfortunately we have to settle for PHPs half baked implementation, but they work ok in this case.


<?
$tutorial=":code.1:
:code.3:
:code.5:
:code.2:";

preg_match_all(":code\.([0-9]*):",$tutorial,$codes);

foreach ($codes[1] as $a){
print "!$a!\n";
}
?>
 
Last edited:
1
•••
And it's trying to take the number out of that sub string. It works GREAT for the first occurance of :code.1:-, but does not continue.

I see a nice fat EXIT at the end of the code in that loop which would cause it to only execute once and then exit.
 
1
•••
AAAAAAAAAAAAA!!!! :lol:

:laugh:! I can't believe I didn't SEE that! Geez! I dunno why I even TYPED that there! LOL .... thanks SOOO much, both of you! ^_^ I must have been :zzz: when I wrote this... geepers...

I'm splitting the 100 NP$ between both of you.

Gosh...

"Introducing.... compuXP's stupidest error! ... the big, fat, EXIT STATEMENT!" Wooo hooo!

NP$ sent! :great:
 
0
•••

We're social

Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back