473,770 Members | 2,144 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Notice: Undefined offset: 49

1 New Member
Hi, I found the code here, it's excately what i am looking for, ie8 give this error "Notice: Undefined offset: 49 in.." which is this line "if ($num_of_chars[49]==$required)", i'm a newbie, i don't know how to overcome this error, so can someone please help me out?
thanks,
Expand|Select|Wrap|Line Numbers
  1. $string = "one two three";
  2. $word_array = explode(" ",$string);
  3. for ($i=count($word_array); $i>=1; $i--)
  4. {
  5. $word = $i == 1 ? " word" : " words";
  6. echo "Strings containing combination of ".$i.$word.":<br>";
  7.  
  8. $flags = array();
  9. $combination_flags = get_combination_flags(count($word_array), $i);
  10. $flags_groups = explode(",",$combination_flags);
  11. foreach ($flags_groups as $val)
  12. {
  13. $temp = chunk_split($val,1,".");
  14. array_push($flags, explode(".", substr($temp,0,(strlen($temp)-1))));
  15. }
  16. for ($j=0; $j<count($flags); $j++)
  17. {
  18. $new_string = "";
  19. for ($k=0; $k<count($word_array); $k++)
  20. $new_string .= $flags[$j][$k] ? " ".$word_array[$k] : "";
  21. trim ($new_string);
  22. echo $new_string."<br>";
  23. }
  24. echo "<br>";
  25. }
  26.  
  27. function get_combination_flags($total, $required)
  28. {
  29. $flag_array = array();
  30. $bin = "";
  31. for ($i=0; $i<$total; $i++)
  32. $bin .= "1";
  33. $dec = bindec($bin);
  34. for ($i=0; $i<=$dec; $i++)
  35. {
  36. $num_of_chars = count_chars(decbin($i), 1);
  37. if ($num_of_chars[49]==$required)
  38. {
  39. $temp = decbin($i);
  40. $length = strlen($temp);
  41. $pre = "";
  42. if ($length<$total) for ($j=$length; $j<$total; $j++) $pre .= "0";
  43. $temp = $pre.$temp;
  44. array_push($flag_array,$temp);
  45. }
  46. }
  47. return implode(",",$flag_array);
  48. }
  49. ?>
  50.  
Jul 3 '10 #1
1 5155
zorgi
431 Recognized Expert Contributor
All that means is that your error_reporting in your php.ini file is set to report notices. There is two ways around this problem. First one is to set your error_reporting so it doesn't report notices:

error_reporting = E_ALL & ~E_NOTICE

that way you turn off all the notices.

OR

You can use extra condition in your if statement:

Expand|Select|Wrap|Line Numbers
  1. if ((isset($num_of_chars[49]))&&($num_of_chars[49] == $required))
  2.  
Jul 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
108841
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still work fine, but with error reporting at all they are marked as errors. Why? What am I doing wrong? www.monkeyclaus.org
2
25825
by: Steven | last post by:
Hi All, I am moving some php code from a Linux machine to a Windows 2000 machine with the code belowe I get the following error : Notice: Undefined offset: 1 in c:\inetpub\wwwroot\test.php on line 5 1) reset($kolom1); 2) while(list($cat,$lnk) = each($kolom1)){ 3) kop($cat);
1
4584
by: google | last post by:
Hello, I'm having major problems trying to get my head round this problem. I'm trying to generate an error free script, however, I still cannot sort out this loop. I get a "Notice: Undefined offset: 24 in c:\inetpub\wwwroot\classes\file.php on line 348"
4
10192
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key, $value) = explode(":", $line, 2);
6
4480
by: nicy12 | last post by:
Hi! my name is Peter. iam working on the php platform. while trying to run and compile a program i get the undefined offset error iam nto much familiar with this error . Please help me . Thanks in advance. Error: Undefined offset: 0 in /es/ePrintsStats/includes/inc.html.cumulative_usage.es.php on line 16 The code: <?php $current_year = date("Y"); $last_year = date("Y")-1;
3
5504
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice: Undefined index: FriendName in D:\Yan\Over_8\SendEmail.php on line 4, Notice: Undefined index: FriendEmail in D:\Yan\Over_8\SendEmail.php on line 5, Notice: Undefined index: Name in D:\Yan\Over_8\SendEmail.php on line 6, Notice: Undefined index: Email...
9
32504
by: simple12 | last post by:
Hello I have a script which have the facility of entering any code to some part of a webpage. I have some problems with it. When i put some code in the script then their is no error shown. When i try to not use a code and leave it empty the following php errors happens. I dont understand why. Help me. Error shown are: - PHP Notice: in file /index.php on line 132: Undefined offset: 4 PHP Notice: in file /index.php on line 141:...
2
2689
by: neridaj | last post by:
Hello, I'm trying to figure out how to get rid of these errors: Notice: Undefined offset: 1 in output_fns.php on line 315 Notice: getimagesize() : Read error! in output_fns.php on line 315 function get_imgdim()
6
18558
by: raydiamond4u | last post by:
Hello. My name is Raymond. My code is generating the following error: Notice: Undefined offset: 2 in C:\wamp\www\imagegallery\supportfile\include\config.php on line 25 How do i correct the error? Here is the code: <?php // Include file for database connectivity $db_server = "localhost";
3
6009
by: razvanel442 | last post by:
Hi all i am new here! I take a look on forum but i don't found a the answer for my problem ok this is my problem: Line47:$user = $_GET; Line48:$pass = $_GET; Line49:$char = $_GET;
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.