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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:13:46+00:00 2026-05-22T15:13:46+00:00

This loop doesn’t seem to be finding the lines I want it to (it’s

  • 0

This loop doesn’t seem to be finding the lines I want it to (it’s not finding anything at all actually).

$file_lines = file("rss.xml");
$max_lines = count($file_lines);
$id = $_POST['id_number'];
$start_string = " <!--".$id."-->";
$start_line;
$end_string = "<!--end of item ".$id."-->";
$end_line;

for ($i = 0; $i < $max_lines; $i++) {
        $temp_line = $file_lines[$i];
        if ($temp_line == $start_string) {
                $start_line = $i;
                echo "found start";
        }

        if ($temp_line == $end_string) {
                $end_line = $i;
                echo "found end";
        }
}

It’s supposed to be going through a file line-by-line and looking to see if it matches a preset string. If it does, it is supposed to set a variable to the position of the line (the counter $i).

  • 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-22T15:13:46+00:00Added an answer on May 22, 2026 at 3:13 pm

    An option is to use array_search:

    $index = array_search($start_string, $file_lines);
    

    $index will be the key of your found element, if any.

    You can check if you have got a result by checking for false:

    if($index !== FALSE) {
        // We have a result, act accordingly. You can get the matched line:
        echo "Line found: " . $file_lines[$index];
    }
    

    As mentioned below, file does not trim line endings. You can use the FILE_IGNORE_NEW_LINES flag to skip this:

    $lines = file("rss.xml", FILE_IGNORE_NEW_LINES);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this example I want to add a .loop({quantity},{sleepvalue}) to a method I got
This is to do with the following code, which uses a for loop to
I'm performing a nested loop in python that is included below. This serves as
I ran into a weird situation today doing some one-time sql code. This nested
I'm working on a shell script that does certain changes on a txt file
This question is language independent. I have an application that handles requests in a
This works (prints, for example, 3 arguments): to run argv do shell script echo
This code outputs the scalars in the row array properly: $line = This is
I'm having trouble with memory in a j2me application. (see another question ) I
I'm trying to write a function that plots a ggplot facet_wrap plot over multiple

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.