Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: str use limiter

  1. #1
    New Coder
    Join Date
    Sep 2007
    Location
    US
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts

    str use limiter

    I'm running into a bit of trouble with this code I recently made, in theory it would have worked fine.

    I need help on how I can get the following done:
    I need to match a changing string and then replace it based on how many times it was previously replaced.
    I've tried many variations of this, here is my most recent:

    PHP Code:
    $i 0;
    $num 0;
    while(
    $num != 600)
    {
       if(
    preg_match('/\[img\](.+?)\[\/img\]/is'$bb2html))
       {
          if(
    $i <= ){
        
    $bb2html preg_replace('/\[img\](.+?)\[\/img\]/is''<img alt="an image" src="\\1"  />'$bb2html);
            
    $i++;
        echo 
    $i.'img let thru';
        }
        if(
    $i 5){
        
    $bb2html preg_replace('/\[img\](.+?)\[\/img\]/is''<a href="\\1">\\1</a>'$bb2html);
            
    $i++;
        echo 
    $i.'img detered';
        }
       }
       else
       {
       
    $num 600
       
    }

    Well the while and preg_match cases seem to work fine but I'm not seeing any filtered results based on how many times that it has been matched.
    I can't think of any other ways to do it, I need a little extra brain power here.

    Thanks all for the help.
    I need to find a book about all this stuff. God, thats gonna be one big book!

    http://www.gamezftw.com
    Play On!

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    $i 0;
    while(
    preg_match('/\[img\](.+?)\[\/img\]/is'$bb2html)){
          if(
    $i <= ){
        
    $bb2html preg_replace('/\[img\](.+?)\[\/img\]/is''<img alt="an image" src="\\1"  />'$bb2html1);
            
    $i++;
        echo 
    $i.'img let thru';
        }elseif(
    $i 5){
        
    $bb2html preg_replace('/\[img\](.+?)\[\/img\]/is''<a href="\\1">\\1</a>'$bb2html);
            
    $i++;
        echo 
    $i.'img detered';
        }
       }

    I add a 1 as "limit" argument to first preg_replace, transform second if in elseif, and replace the while condition, last ones for beauty,

    best regards
    Last edited by oesxyl; 12-28-2007 at 05:53 AM.

  • #3
    New Coder
    Join Date
    Sep 2007
    Location
    US
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Haha, thanks, You've made me feel like a total fool.
    That one was obvious enough... I can't believe I over looked that one.

    This means its either time for sleep, or more coffee.
    Thanks again
    I need to find a book about all this stuff. God, thats gonna be one big book!

    http://www.gamezftw.com
    Play On!


  •  

    Posting Permissions

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