alfii Posted March 8, 2012 Share Posted March 8, 2012 hey guys! I just got started with php (yesterday) and im currently trying to write a script that cuts email signatures off. The first filter ($sig[0]) works fine, the string is cut and posted- and, well, that's it. I think i did sth wrong within the for- but i cant find it. So please help me out. A hint would be fine already. Thanks in advance- and here is some code: <?php $string="TESTSTRING!! I AM AN EMAIL TEXT!!! SO RANDOM! --- I AM A SIGNATURE!! HERP DERP CUT ME OFF"; //define possible sig starts (=filter) $sig[0]=("#=="); $sig[1]=("---"); $sig[2]=("the name of an enterprise"); $sig[3]=("___"); for ($i=0; $i<=3; $i++) { /* or count($sig) ? */ $sigpos=strpos($string,$sig[$i]); if($sigpos>0) { $string= substr($string,0,$sigpos); break; echo $string; } else { echo $string; break; } } ?> <br> <? //show where the sig is cut off echo $sigpos; ?> Link to comment https://forums.phpfreaks.com/topic/258525-issues-with-for-warning-noob-question/ Share on other sites More sharing options...
AyKay47 Posted March 8, 2012 Share Posted March 8, 2012 remove the break; that you have in the else condition. If $sig[0] does not match, the break; will break you out of the for loop and no other $sig values will be compared. $string = 'TESTSTRING!! I AM AN EMAIL TEXT!!! SO RANDOM! --- I AM A SIGNATURE!! HERP DERP CUT ME OFF'; //define possible sig starts (=filter) $sig[0]=("#=="); $sig[1]=("---"); $sig[2]=("the name of an enterprise"); $sig[3]=("___"); for ($i=0; $i <= count($sig); $i++) { $sigpos = strpos($string,$sig[$i]); if($sigpos !== false) { $string = substr($string,0,$sigpos); echo trim($string); break; } } echo "<br />"; //show where the sig is cut off echo $sigpos; ?> Link to comment https://forums.phpfreaks.com/topic/258525-issues-with-for-warning-noob-question/#findComment-1325196 Share on other sites More sharing options...
alfii Posted March 8, 2012 Author Share Posted March 8, 2012 $me=stupid; break; thanks alot! Link to comment https://forums.phpfreaks.com/topic/258525-issues-with-for-warning-noob-question/#findComment-1325199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.