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 6694333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:05:22+00:00 2026-05-26T06:05:22+00:00

I was maintaining some code using ereg, and made the migration to preg_match (not

  • 0

I was maintaining some code using ereg, and made the migration to preg_match (not forgetting the delimiter), but it broke my function.

Here is my original function, which take a file, and create a cropped copy which stopped after lines only composed of # are encountered 6 times:

function createStrippedFile($path1, $path2)
{
    $lines = file($path1);

    $handle = fopen($path2,"w");

    // 6
    $index = 0;

    foreach ($lines as $line)
    {
        $line = trim($line);

        if ($index != 7)
            fwrite($handle,$line."\r\n");

        if (ereg("^[#]+$",$line) !== FALSE)
            ++$index;
    }

    fwrite($handle,"END OF DOC\r\n");
    fclose($handle);
}

In this code I changed:

if (ereg("^[#]+$",$line) !== FALSE)

by

if (preg_match('/^[#]+$/',$line) !== FALSE)

but now it isn’t cropping anymore. Is there anything I missed when doing the transition?

PS: If someone know of a better way to do what I’m trying to do, he can also write it.

  • 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-26T06:05:23+00:00Added an answer on May 26, 2026 at 6:05 am

    It seems the problem is preg_match returns 0 in case there’s no matches, and 0 !== FALSE. I would try to remove this code “!== FALSE” and check if it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen both done in some code I'm maintaining, but don't know the difference.
It is Hallowe'en after all. Here's the problem: I'm maintaining some old-ish J2EE code,
I have the following function from some legacy code that I am maintaining. long
My site is going to have some inline code (when using the foo() function...)
Here's a snippet of code that I saw in some code I'm maintaining. Object
I'm maintaining some code that uses a *= operator in a query to a
I am currently maintaining some code, which is likely to be refactored soon. Before
I'm currently maintaining some flex code and noticed very many functions which are declared
Looking at some code I'm maintaining in System Verilog I see some signals that
In some Delphi 7 code I am maintaining, I've noticed a lot of instances

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.