Solved

How do I fix "Undefined offset: 1"

Posted on 2011-09-08
3
446 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

740 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