473,513 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with str_replace or strpos

14 New Member
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
2 1758
rpnew
188 New Member
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
daschicken
14 New Member
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

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

Similar topics

3
1965
by: mudge | last post by:
I'm having a problem getting rid of newlines. say I have this situation: $cat = "A nice\n cat"; The "\n" is an escape character which creates a newline right there. Now, how would I get...
3
1360
by: Craft | last post by:
have this code and I'm trying to get it to work. It mostly works, but $serverpop does not seem to work. What it looks to me like this code does is scan http://www.worldofwarcraft.com­/serverstatus/...
1
6829
by: George Hester | last post by:
This has just started. I don't recal installing any updates or security fixes lately. But I am getting a script debugger notification just appearing on the desktop from dllhost. What this is is...
15
1916
by: NurAzije | last post by:
I have written a code and can't figure what is wrong, the code will read a content of a file and cut all the emails from it,then echo them, but I have a problem with '"' charecter I think.. Take a...
3
2036
by: julian_m | last post by:
file AddHTML.htm: ---------------------------- This line is <b>ok</b><br> This line is <b>ok</b><br> This line is <b>ok</b><br> <?PHP echo "This one has code prohibited "; ?> This line is...
3
2134
by: webEater | last post by:
Hey, I am writing a file that reads in an external file in the web and prints it out including the response header of the http protocol. I do this to enable cross domain XMLHttpRequests. I...
1
1524
by: Promextheus Xex | last post by:
First php post... Hi there, I'm writing some code for my website to list people listening to my music. I have a loop for an array that dosen't seem to display all people. most of the time it...
2
2637
by: john6630 | last post by:
When I run the following code, I get "Undefined variable: localPath" error. I do not understand why? It seems simple enough...but I am new to PHP so any help is appreciated. I am running PHP...
5
1990
by: vtp82 | last post by:
I am vaibhav here i am a .net developer. I need help if anybody can I am having one php code that I need to convert in asp.net. but I do not understand what actually they had done in php so if...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.