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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.