Problem with str_replace or strpos

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daschicken
    New Member
    • Jan 2008
    • 14

    Problem with str_replace or strpos

    Hi,
    ive written the following php code. its a part of an admin form to add a text.
    when adding the text %bild[xx] the script is supposed to swap that with the link to the picture already stored in the mysql db.

    it works perfectly fine until the $id variable reaches "100".
    I dont understand why it works for every number from 1 till 99 but not for a bigger one than 100.
    I mean $id is not fixed to two digits.

    Code:
    	
            $text = $_POST['text'];
            $get = 'SELECT * FROM bild order by bild_id desc';
            $select = mysql_query($get, $link);
    
            $bildende = (mysql_num_rows($select)+1);
            $id = 1 ;
            while($id < $bildende)
            {
            $findme   = "%bild[$id]";
            $pos = strpos($text, $findme);
            if ($pos === false) { }
            else {
            $get2 = "SELECT bild FROM bild where bild_id='$id'";
            $repl = mysql_query($get2, $link);
            $repl = mysql_fetch_array($repl);
            $repl = $repl['bild'];
            $repl1 = "%bild[$id]";
            $text = str_replace($repl1,$repl,$text);
            }
                $id++;
            }
    Anybody any idea?
    Thanks!
  • rpnew
    New Member
    • Aug 2007
    • 189

    #2
    Originally posted by daschicken
    Hi,
    ive written the following php code. its a part of an admin form to add a text.
    when adding the text %bild[xx] the script is supposed to swap that with the link to the picture already stored in the mysql db.

    it works perfectly fine until the $id variable reaches "100".
    I dont understand why it works for every number from 1 till 99 but not for a bigger one than 100.
    I mean $id is not fixed to two digits.

    Code:
    	
            $text = $_POST['text'];
            $get = 'SELECT * FROM bild order by bild_id desc';
            $select = mysql_query($get, $link);
    
            $bildende = (mysql_num_rows($select)+1);
            $id = 1 ;
            while($id < $bildende)
            {
            $findme   = "%bild[$id]";
            $pos = strpos($text, $findme);
            if ($pos === false) { }
            else {
            $get2 = "SELECT bild FROM bild where bild_id='$id'";
            $repl = mysql_query($get2, $link);
            $repl = mysql_fetch_array($repl);
            $repl = $repl['bild'];
            $repl1 = "%bild[$id]";
            $text = str_replace($repl1,$repl,$text);
            }
                $id++;
            }
    Anybody any idea?
    Thanks!
    Hi,
    Tell me one thing first.......... that. whethere your while loop is going beyong... 100 ?? i mean you've put the while condition like ($id<$bildende) are you going beyond that? what is the value you are getting for $bildende

    Regards,
    RP

    Comment

    • daschicken
      New Member
      • Jan 2008
      • 14

      #3
      hi,

      the var $bildende is defined as the length of the table in the db.

      so its always supposed to run the while loop till the end of the table

      Comment

      Working...