?
Solved

How do I fix "Undefined offset: 1"

Posted on 2011-09-08
3
Medium Priority
?
449 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 600 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 1400 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

770 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