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

  • Home
  • SEARCH
  • 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

Basically i got this for loop and i want the number inputed (eg. 123)
I want to convert this linear loop into a concurrent one: for(Item item :
Python noob; please explain why this loop doesn't exit. for i in range(0,10): print
I have this loop running after a click(), and it does not return false
I want to write this bash loop for zsh while true; do echo print
In this example I want to add a .loop({quantity},{sleepvalue}) to a method I got
This loop checks if a record is in the sqlite database and builds a
Why was this loop introduced in java?Is it a java creation? What is its
/// \todo Loop must be rewritten ... /// \todo Delete this loop Can Doxygen
So I dynamically create 3 UIButtons (for now), with this loop: NSMutableArray *sites =

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.