By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,081 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,081 IT Pros & Developers. It's quick & easy.

Problem with str_replace or strpos

P: 14
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2.         $text = $_POST['text'];
  3.         $get = 'SELECT * FROM bild order by bild_id desc';
  4.         $select = mysql_query($get, $link);
  5.  
  6.         $bildende = (mysql_num_rows($select)+1);
  7.         $id = 1 ;
  8.         while($id < $bildende)
  9.         {
  10.         $findme   = "%bild[$id]";
  11.         $pos = strpos($text, $findme);
  12.         if ($pos === false) { }
  13.         else {
  14.         $get2 = "SELECT bild FROM bild where bild_id='$id'";
  15.         $repl = mysql_query($get2, $link);
  16.         $repl = mysql_fetch_array($repl);
  17.         $repl = $repl['bild'];
  18.         $repl1 = "%bild[$id]";
  19.         $text = str_replace($repl1,$repl,$text);
  20.         }
  21.             $id++;
  22.         }
  23.  
  24.  
Anybody any idea?
Thanks!
Feb 4 '08 #1
Share this Question
Share on Google+
2 Replies


rpnew
100+
P: 188
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2.         $text = $_POST['text'];
  3.         $get = 'SELECT * FROM bild order by bild_id desc';
  4.         $select = mysql_query($get, $link);
  5.  
  6.         $bildende = (mysql_num_rows($select)+1);
  7.         $id = 1 ;
  8.         while($id < $bildende)
  9.         {
  10.         $findme   = "%bild[$id]";
  11.         $pos = strpos($text, $findme);
  12.         if ($pos === false) { }
  13.         else {
  14.         $get2 = "SELECT bild FROM bild where bild_id='$id'";
  15.         $repl = mysql_query($get2, $link);
  16.         $repl = mysql_fetch_array($repl);
  17.         $repl = $repl['bild'];
  18.         $repl1 = "%bild[$id]";
  19.         $text = str_replace($repl1,$repl,$text);
  20.         }
  21.             $id++;
  22.         }
  23.  
  24.  
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
Feb 4 '08 #2

P: 14
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
Feb 7 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.