Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 10.04.07 11:38 
Ich sitze schon eine ganze Weile an einem Problem in php:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
//Initialize $pos
$pos = 0;
//While [ is found
while ($pos > -1) {
  //start at beginning
  if ($pos == 0) 
    $pos = strpos('[[[','[');
  else  
           //start at $pos
    $pos = strpos('[[[','[',$pos);
  // if character isn't found leave the loop
  if ($pos === false) $pos = -1; //here seems to be the mistake =(
        // Add $pos to array
  $open_br_pos[] = $pos;
  echo $pos."<br>";
  $pos++;
    }

Der String '[[[' soll nach '[' durchsucht werden und die Positionen der gefundenen [ soll in ein Array geschrieben werden.
Alles endet in einer Endlosschleife. Ich vermute das Problem in der markierten Zeile. Das dreifache = verwende ich, weil es im PHP-Manual so steht.
Wer kann mir helfen?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 10.04.07 12:28 
In Zeile 12 sollte $pos = -2; stehen ;-) Oder Du änderst die Abbruchbedingung nach $pos === false und schreibst in Z12 einfach nur Continue; hin ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 10.04.07 12:36 
Ich verstehe -2 nicht. :gruebel:
Wenn $pos -1 ist, dann ist die Abbruchbedingung doch falsch und die Schleife hört auf. Oder nicht? Warum dann -2? -1 reicht doch.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 10.04.07 12:58 
user profile iconMarco D. hat folgendes geschrieben:
Ich verstehe -2 nicht. :gruebel:
Wenn $pos -1 ist, dann ist die Abbruchbedingung doch falsch und die Schleife hört auf. Oder nicht? Warum dann -2? -1 reicht doch.


Schau mal in die letzte Zeile deiner Schleife :P

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 10.04.07 16:10 
user profile iconBenBE hat folgendes geschrieben:
Schau mal in die letzte Zeile deiner Schleife :P

:lol: Ja, ich sehe das Übel. :lol:
Danke für die Hilfe :!: ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot