3 Replies - 1734 Views - Last Post: 31 July 2009 - 03:56 PM Rate Topic: -----

#1 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 543
  • Joined: 21-December 08

Undefined offset error

Posted 31 July 2009 - 10:03 AM

I get this error "Notice: Undefined offset: 2 in ..." throughout my web site. I just don't see where's the problem because i have looked and looked again at my code, i have tested it and i don't see any reason for this error.
This error doesn't affect my results in any way, I mean if they didn't show up, it would be perfect. So..., how can i supress this kind of error? I mean what must i write so that it doesn't show up anymore?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Undefined offset error

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Undefined offset error

Posted 31 July 2009 - 10:07 AM

Can you show the code that's generating the error. Undefined Offset error means the same thing in a numeric array as Undefined Index in an associative array
Was This Post Helpful? 0
  • +
  • -

#3 livium  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 543
  • Joined: 21-December 08

Re: Undefined offset error

Posted 31 July 2009 - 10:14 AM

View PostPsychoCoder, on 31 Jul, 2009 - 09:07 AM, said:

Can you show the code that's generating the error. Undefined Offset error means the same thing in a numeric array as Undefined Index in an associative array



I have found what to write so that those messages don't show up any more: ini_set('display_errors',0);
Of course I wished i knew why i get these errors. The code is complicated. These are the two functions, from which the first one generates the undefined offset error on line ( if (strtolower($vector_string[$i])==strtolower($word)) :

the function highlight makes  words ( generated by get_initial_match_word )  in a string blue if it is found, and the function  get_initial_match_word, returns all the words which are identical with $word in all cases ( i mean Aa =aa):  


function get_initial_match_word ($word, $string)
{
$vector_string=array_unique(explode(" ",preg_replace('/\s\s+/',' ',trim($string))));	
$vector_match=array(null);
$j=0;

if (count($vector_string)>=1)
for ($i=0; $i<=count($vector_string)-1; $i++)
 {
	 
  if (strtolower($vector_string[$i])==strtolower($word)) {
		  $vector_match[$j]=$vector_string[$i]; 
		  $j++;
	  }	
	 }
return $vector_match;
}

function highlight ($string_search, $string)
{
echo '1 ';
$vector_init=array(null);	
if ($string_search!="") {	
	   $words=array_unique(explode(" ",preg_replace('/\s\s+/',' ',$string_search)));
	
	
	
	for ($i=0; $i<=count($words)-1; $i++)
		{
		
		$string=str_replace("."," .",$string);
		$vector_init=get_initial_match_word($words[$i],$string);
		
		
if (count($vector_init)>=1)
			for ($j=0; $j<=count($vector_init)-1; $j++)  
			{
			$string=str_replace(" ".$vector_init[$j]." ",' <font color="blue"><b>'.$vector_init[$j].'</b></font> ',$string);
			}
		$string=str_replace(" .",".",$string);	
	
		}
	
}
return $string;
}



This post has been edited by livium: 31 July 2009 - 10:15 AM

Was This Post Helpful? 0
  • +
  • -

#4 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Undefined offset error

Posted 31 July 2009 - 03:56 PM

to ignore the E_NOTICE rather than disabling all errors being displayed you can use

error_reporting(E_ALL ^ E_NOTICE);



which will show all errors EXCEPT E_NOTICEs
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1