Solved

How do I fix "Undefined offset: 1"

Posted on 2011-09-08
3
448 Views
Last Modified: 2012-05-12
Experts:

How do I fix a "Undefined offset: 1"?   What exactly is it?   I do not see a visible error in my code...

Thanks for your help!

preg_match('%<tr>\s*<td align="center">\s*<a href="http:\/\/www\.website\.com\/CatList\.asp"><span class="prodListPage_catName">Product Categories<\/span><\/a><span class="prodListPage_catName">\&gt<\/span><a href=".*?"><span class="prodListPage_catName">(.*?)<\/span><\/a><span class="prodListPage_catName">\&gt<\/span><a href=".*?"><span class="prodListPage_catName">(.*?)<\/span><\/a><span class="prodListPage_catName">\&gt<\/span><a href=".*?"><span class="prodListPage_catName">(.*?)<\/span><\/a>\s*<\/span><\/td>\s*<\/tr>%',$buffer2,$matches2001);

    $category = $matches2001[1];     //Undefined offset: 1 here
    $subcategory = $matches2001[2];    //Undefined offset: 2 here
    $subsubcategory = $matches2001[3];     //Undefined offset: 3 here

Open in new window

0
Comment
Question by:rlb1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Assisted Solution

by:haloexpertsexchange
haloexpertsexchange earned 150 total points
ID: 36505628
it means that the array keys of 1, 2, and 3 do not exist. Try doing a print_r($matches2001) to see what it is that you have in that array.

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 350 total points
ID: 36505661
Perhaps you should be checking the return value of the call to preg_match:
if (preg_match('%<tr>\s*<td align="center">\s*<a href="http:\/\/www\.website\.com\/CatList\.asp"><span class="prodListPage_catName">Product Categories<\/span><\/a><span class="prodListPage_catName">\&gt<\/span><a href=".*?"><span class="prodListPage_catName">(.*?)<\/span><\/a><span class="prodListPage_catName">\&gt<\/span><a href=".*?"><span class="prodListPage_catName">(.*?)<\/span><\/a><span class="prodListPage_catName">\&gt<\/span><a href=".*?"><span class="prodListPage_catName">(.*?)<\/span><\/a>\s*<\/span><\/td>\s*<\/tr>%',$buffer2,$matches2001)) {
    $category = $matches2001[1];     //Undefined offset: 1 here
    $subcategory = $matches2001[2];    //Undefined offset: 2 here
    $subsubcategory = $matches2001[3];     //Undefined offset: 3 here
}

Open in new window

0
 

Author Closing Comment

by:rlb1
ID: 36507096
Thanks for your help!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question