Solved

How do I fix "Undefined offset: 1"

Posted on 2011-09-08
3
441 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
3 Comments
 
LVL 13

Assisted Solution

by:haloexpertsexchange
haloexpertsexchange earned 150 total points
Comment Utility
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 74

Accepted Solution

by:
käµfm³d   👽 earned 350 total points
Comment Utility
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
Comment Utility
Thanks for your help!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now