473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

undefined offset:2

hello all..

I am using luminous php syntax highlighter in my codeigniter project. It is working i.e. it highlights the codes. But an error also encountered --

A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2
Filename: ci-syntax-highlight/highlight.php
Line Number: 30

Array ( )
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2
Filename: ci-syntax-highlight/highlight.php
Line Number: 30

can anyone help me out???
Jan 5 '12 #1
7 10068
johny10151981
1,059 1GB
you are trying to access array, but the index you are using is not valid.

say, you have defined
Expand|Select|Wrap|Line Numbers
  1. $array[0]='asdf';
  2. $array[1]='**';
Now you are trying to access:
Expand|Select|Wrap|Line Numbers
  1. echo $array[2]; //but index 2 does not exists
  2.  
Jan 5 '12 #2
thanx johny...

but i m not getting this point in my code....
here's the highlight.php -


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /* place in application/config/hooks.php:
  4. $hook['display_override'] = array(
  5.   'class' => 'highlight',
  6.   'function' => 'hook',
  7.   'filename' => 'highlight.php',
  8.   'filepath' => 'hooks/ci-syntax-highlight',
  9.   'params' => array()
  10. );
  11. */
  12. class highlight {
  13.  
  14.   public function highlight() {
  15.     if (!class_exists('luminous')) {
  16.       require_once dirname(__FILE__) . '/luminous/luminous.php';
  17.     }
  18.   }
  19.   private function hook_cb($matches) {
  20.     $meta = $matches[2];
  21.     $code = $matches[3];
  22.  
  23.     // parse the classes, don't worry about this if it's a [code] 
  24.     if (strlen($matches[0]) && $matches[0][0] === '<') {
  25.       // code in <...> tags are legit. html so we need to unescape whatever they
  26.       // had to escape
  27.       $code = htmlspecialchars_decode($code);
  28.       preg_match('/class=([\'"])(.*?)(\\1)/', $meta, $m);
  29.       print_r($m);
  30.       $classes = preg_split('/\s+/', $m[2]);
  31.       if (!in_array('highlight', $classes)) return $matches[0];
  32.     }
  33.     $language = 'plain';
  34.     if (preg_match('/lang(uage)?=(.*)/', $meta, $m)) {
  35.       $language = $m[2];
  36.       if (strlen($language) && ($language[0] === '"' || $language[0] === "'")) {
  37.         if (($pos = strpos($language, $language[0], 1)) !== false) {
  38.           $language = substr($language, 1, $pos-1);
  39.         }
  40.       }
  41.     }
  42.     return luminous::highlight($language, $code);
  43.   }
  44.  
  45.   public function hook($params = array()) {
  46.     $CI = & get_instance();
  47.     $output = $CI->output->get_output();
  48.     if (!isset($params['header']) || $params['header'] === true) {
  49.       if (isset($params['theme'])) 
  50.         luminous::set('theme', $params['theme']);
  51.       if (!function_exists('base_url')) {
  52.         $CI->load->helper('url');
  53.       }
  54.       luminous::set('relative-root', 
  55.         base_url() . 'application/hooks/ci-syntax-highlight/luminous/');
  56.       $head = luminous::head_html();
  57.       // insert the stylesheets
  58.       $output = preg_replace('%</head%i',
  59.         "$head\n" . '$0', $output, 1);
  60.     }
  61.     $exps = array(
  62.       //  .. 
  63.       "/
  64.         \[(code)(.*?)\][ \t]*(?:[\r\n]|\r\n)?
  65.         (.*?)
  66.         \s*
  67.         \[\/code\]
  68.       /xs",
  69.       // <pre> or <code>
  70.       "/
  71.         <(pre|code)(.*?)>[ \t]*(?:[\r\n]|\r\n)?
  72.         (.*?)
  73.         \s*
  74.         <\/\\1>
  75.       /xs");
  76.     foreach($exps as $e) {
  77.       $output = preg_replace_callback($e, array($this, 'hook_cb'), $output);
  78.     }
  79.     echo $output;
  80.   }
  81. }
Jan 5 '12 #3
nd i m getting error in this line -

$classes = preg_split('/\s+/', $m[2]);
plz help me out...
Jan 5 '12 #4
Dormilich
8,658 Expert Mod 8TB
seems like there is no second match. what does the print_r() give you?
Jan 5 '12 #5
thanx Dormilich..

print_r output -

Expand|Select|Wrap|Line Numbers
  1. Array (
  2.  [0] => class='highlight'
  3.  [1] => '
  4.  [2] => highlight
  5.  [3] => ' 
  6. // some more repetitions of that
Jan 5 '12 #6
Dormilich
8,658 Expert Mod 8TB
are you sure it’s line #28? the error doesn’t make sense in this context.
Jan 5 '12 #7
yes , error comes in line -
$classes = preg_split('/\s+/', $m[2]);
Jan 5 '12 #8

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

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
1
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading...
4
by: Mike | last post by:
I am having a problem when a field is spaces being undefined. I wasn't sure if the problem was Excel or Javascript, so I thought I would post here first. The users are able to select from a drop...
1
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
1
by: Foolster41 | last post by:
I'm rather new to C++ programing. I'm using the dev-C++ program on a windows XP OS. I'm trying to compile the code for a multi user dungeon (MUD) called circle-mud. When I compile I get the...
13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
4
by: Chris Beall | last post by:
If you want your code to be bulletproof, do you have to explicitly check for the existence of any possibly-undefined variable? Example: window.outerHeight is defined by some browsers, but not...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
3
by: Michael Sgier | last post by:
Hi i get thousands of messages like below. How shall i resolve that? Thanks Mcihael Release/src/Utility/RawImage.o: In function `CMaskImage::CMaskImage(int, int, char const*)':...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.