Jump to content

issues with for [warning: noob question]


alfii

Recommended Posts

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

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;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.