For Loop

Links for php scripts

Moderators: macek, egami, gesf

supereman16
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Apr 10, 2012 8:52 pm

For Loop

Postby supereman16 » Tue Apr 10, 2012 9:10 pm

Hi guys. This is my for loop.

Code: Select all

...
$content = $row['post_content'];
   for ($i = 0, $end = "false"; $end == "false"; $i++)
   {
      if (strstr($content['$i'],'['))
      {
         echo do_shortcode('[frax09alpha]');
         $end = 'true';
      }
      else
      {
         echo $content['$i'];
         $end = 'false';
      }
   }
...

Every time I try to go to the page that this is on, my computer slows down a lot and then firefox starts to not respond. Its on a page on my wordpress website through php snippets plugin. I've narrowed down the problem to this little bit because everything was working fine until I put this in the script. I'm confused at what the problem could be.
I am accessing lots of different bits of info from a wordpress mysql database and at this point I want to read each individual letter and write it until I come to a [ which is the start of a shortcode and then "do" the shortcode with the do_shortcode() wordpress function.
I used to have the "haystack" and "needle" in the strstr() function switched around. Is that correct or am I right now.
Thanks for the help. You won't be able to look at the page because it's private. any help would be appreciated. I'm 14 and started coding about a year and a half ago off and on. :help:
Ethan

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: For Loop

Postby egami » Wed Apr 11, 2012 4:27 am

that's bad syntax.

use a while loop and not a for loop..


while ($end !== TRUE) {
do this...
if ($var == "something") {
$end = TRUE;
} // kills the while..
}


Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests