Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:04:56+00:00 2026-05-28T04:04:56+00:00

I am using a lib which uses $pattern = LIMIT[^\w]{1,}([0-9]{1,})([\,]{0,})([0-9]{0,}); $replacement = ; eregi($pattern,

  • 0

I am using a lib which uses

$pattern = "LIMIT[^\w]{1,}([0-9]{1,})([\,]{0,})([0-9]{0,})";
        $replacement = "";
        eregi($pattern, $query, $regs);
        $query = eregi_replace($pattern, $replacement, $query);

        if($regs[2])
            $query = str_ireplace("SELECT ", "SELECT TOP ".$regs[3]." ", $query);
        else
            {
            if($regs[1])
                $query  = str_ireplace("SELECT ", "SELECT TOP ".$regs[1]." ", $query);
            }

I change some part of the code to

$pattern = "/LIMIT[^\w]{1,}([0-9]{1,})([\,]{0,})([0-9]{0,})/i";
        $replacement = "";
        preg_match($pattern, $query, $regs);

But now I got error messages saying “Undefined offset: 2” and “Undefined offset: 1”

I think moving from eregi to preg_match should be easy…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:04:56+00:00Added an answer on May 28, 2026 at 4:04 am

    There is no issue with preg_match or preg_replace or your regex.

    You get this error when $query doesn’t match at all (e.g. $query="SELECT foo FROM bar").
    Then $regs is an empty array, so accessing $regs[2] results in an error since there are no elements in it to begin with.

    I’d suggest using count($regs) to see whether to even do the $regs[2] thing.

    $query="SELECT asdf FROM foo";
    $pattern = "/LIMIT[^\w]{1,}([0-9]{1,})([\,]{0,})([0-9]{0,})/i";
    $replacement = ""; 
    preg_match($pattern, $query, $regs);
    $query = preg_replace($pattern, $replacement, $query);
    
    
    if( count($regs)>=0 ) {
        if($regs[2])
        // ... etc the #$egs[2] $regs[1] code here.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a lib which uses eregi($match=^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$,$line,$matches) but as eregi is
I'm using the PHPExcel lib which it seems to do great jobs, but in
In my project, I'm using HTML_ToPDF PHP class, which uses html2ps script to convert
I have a tinyMCE editor which uses the advanced theme. I am using the
I am trying to debug (using gdb) a multi-threaded program, which uses POSIX threads.
Normally in MATLAB I can compile a mex file which uses OpenCV functions using:
I'm using a MinGW-based GCC cross-compiler to compile a project which uses SCons as
I'm using a JAR file of my own, which uses a Java library (JHDF5),
Let's say I have a library Lib.dll, which uses Castle.Windsor to initialize its services.
I'm using valgrind to debug a binary which uses loadable libraries via dlopen. On

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.