Results 1 to 5 of 5

Thread: Looping

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Looping

    I have this code:

    PHP Code:
    <?php
    include('snippets/format.php');
    $crap "Text!\n(code)Private Sub Form_Load()(/code)Text is cool!" "\n(code)Dim strString As String(/code)";
    if (
    strpos($crap"(code)") == false) {
        echo 
    "no";  
    } else {
        do {
            
    $j strpos($crap"(code)");
            if (
    $j == false) {
                break;
            }
            
    $k strpos($crap"(/code)"$j);
            
    $line substr($crap$j +6$k 12);
            
    $code $line//format($line);
            
    $crap str_replace("(code)" $line "(/code)"$code$crap);
        } while (
    $j != false);
        echo 
    $crap;
    }
    ?>
    Which searches through $crap to find all the (code) tags and replace what's between them with formatted text, like is done in these posts.

    However it just loops indefinetly and never catches more than one (code) tag.
    Last edited by The Hobo; Apr 26th, 2002 at 10:44 AM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    This may or may not be your entire problem but you may want to fix this line:
    PHP Code:
    $j strpos($crap"[ code] "); 
    to
    PHP Code:
    $j strpos($crap"[ code ] "); 
    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    It's not that way in my code, I had to put spaces in there otherwise the forums would put all that within code tags. I'll go through and edit to to make it look better.

    Any ideas would be really helpful.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236
    Change
    Code:
    $line = substr($crap, $j +6, $k - 12);
    to
    Code:
    $line = substr($crap, $j +6, $k - $j - 6);
    That should fix it.
    What is the answer to this question?

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Beautiful! I think that corrected it. Thanks alot, Martin.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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