So my problem is not the text which gets assigned to a variable. I originally thought it was chopping data but it my function that is messed up. Here it is, please tell me if there is any way I can rewrite it to make it better. It's the first function i've ever written.
function charsbefaft($srchword,$str1,$int)
{
//This function searches the returned data for the search word and returns
//a designated set of chars before and after the search word.
$str2 = split(" ",$str1);
$srchword2=array_search($srchword,$str2);
$num1=$srchword2 + $int;
$num2=$srchword2 - $int - 1;
if ( $num2<0 ) {
$num2=0;
}
while ( $num2 < $num1 )
{
echo $str2[$num2];
echo " ";
$num2=$num2+1;
}
}