Results 1 to 9 of 9

Thread: [RESOLVED] PHP While....Loop - Help Needed

  1. #1

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Resolved [RESOLVED] PHP While....Loop - Help Needed

    hi guyz, i have this question like;

    In ASP there is something like
    Code:
    Do While arg
    
    some more codes...
    
    Loop
    what that does in ASP/VB is that it loops until the argument is false

    and i thought it should be doing the same thing with PHP's while function

    but it doesn't instead it loops forever.

    take this code for example;

    Code:
    'Note that this is an ASP Code
    strPost = "[EDIT]C:\Program Files\bpmp\htdocs\smat_3.jpg[/EDIT]"
    Do While InStr(1, strPost, "[EDITED]", 1) > 0 AND InStr(1, strPost, "[/EDITED]", 1) > 0
    
    'some more codes...
    
    Loop
    but if i try that in PHP using the While....Loop then it loops for ever

    pls note the function InStr() function,this is used to check if a given string occurs in another string and also it returns the position where the occurence starts and i have a similar php function that does that.
    here it is.

    PHP Code:
    function InStr($string,$find,$CaseSensitive false) {
            
    $i=0;
            while (
    strlen($string)>=$i) {
                unset(
    $substring);
                if (
    $CaseSensitive) {
                    
    $find=strtolower($find);
                    
    $string=strtolower($string);
                }
                
    $substring=substr($string,$i,strlen($find));
                if (
    $substring==$find) return $i;
                
    $i++;
            }
            return -
    1;
        } 
    Last edited by modpluz; May 3rd, 2006 at 09:42 PM.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP While....Loop - Help Needed

    Use strpos() and stripos() to do an Instr.

  3. #3

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: PHP While....Loop - Help Needed

    it still does the same thing...it loops forever
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP While....Loop - Help Needed

    You don't need to write your own InStr function.

  5. #5

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: PHP While....Loop - Help Needed

    ok...am now using strpos() and it still does the same thing
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: PHP While....Loop - Help Needed

    I am sorry that I can't post as long a post as I would like to explain.
    strpos() and stripos() are builtin PHP functions that do what InStr does.
    strpos() is case-sensitive and stripos() is not.

    You would write this:
    VB Code:
    1. InStr(1, strPost, "[EDITED]", 1)


    like this:
    PHP Code:
    strpos($strPost'[EDITED]'
    - it's the same function.


    So there is no need to write your own function as they are already built in.


    edit: Thanks for the merge Rob
    Last edited by penagate; May 4th, 2006 at 07:35 AM.

  7. #7

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: PHP While....Loop - Help Needed

    found a way to do this, instead of using the strpos() function, i did it this way.
    i checked the string for all matches of [EDITED] by using the preg_match_all() function after which i used For...Loop to loop through the string and change whatever i wish to change.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] PHP While....Loop - Help Needed

    Whats wrong with the strpos function? - it is a lot faster than pregh_match_all which actually, compiles, searches and stores internally the positon of every occurance of [EDITED] in the string.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: [RESOLVED] PHP While....Loop - Help Needed

    thanks...i don't know why it doesn't work for me.strpos() does get the position where the string [EDITED] started(i think).
    but what if i have more than one [EDITED] in my string?
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

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