| Autor |
Beitrag |
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Di 10.04.07 11:38
Ich sitze schon eine ganze Weile an einem Problem in php: C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
| $pos = 0; while ($pos > -1) { if ($pos == 0) $pos = strpos('[[[','['); else $pos = strpos('[[[','[',$pos); if ($pos === false) $pos = -1; $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
      
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: 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. 
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Di 10.04.07 12:36
Ich verstehe -2 nicht.
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
      
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Di 10.04.07 12:58
_________________ 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. 
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Di 10.04.07 16:10
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
|