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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:41:17+00:00 2026-05-27T02:41:17+00:00

I wrote a php search script on my site for checking to see if

  • 0

I wrote a php search script on my site for checking to see if a package exists in a text file or not (I used file_get_contents.) It takes what the user entered and combines it with the string ‘BUILD: ‘ Below is an example of the file and I’ll explain in the paragraph following it:

BUILD: packageA
URL: www.package-a.com

BUILD: packageB
URL: www.package-b.com

BUILD: packageC
URL: www.package-c.com

So if a user were to search “packageB”, it would be combined with “BUILD: ” making the variable I’m testing with have the value: “BUILD: packageB”. I have a conditional saying if that string exists or not; everything’s working good on that end.

My question/problem is how can I list the URL: line beneath it with an echo? I’ve been testing some ideas with strlen() and I can’t seem to get it and the text file has different strlens for entry. Is there a way to make PHP force a "nextLine()" if there is such a thing… does PHP recognize return delimits?

Thank you!

  • 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-27T02:41:17+00:00Added an answer on May 27, 2026 at 2:41 am
    // The string you are searching for
    $package = 'packageB';
    
    // Get the file into an array
    $data = file('myfile.txt');
    
    // Loop the data
    for ($i = 0, $found = FALSE; isset($data[$i]); $i++) {
      if (trim($data[$i]) == "BUILD: $package") { // We found the one we're looking for
        echo trim($data[++$i]); // Echo the next line
        $found = TRUE;
        break; // Stop looping
      }
    }
    
    if ($found) {
      echo "<br />\nI found the URL on line $i";
    } else {
      echo "I didn't find it!";
    }
    

    file() gets the file data as an array where each element is one line of the file, unlike a single string like file_get_contents() returns.

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

Sidebar

Related Questions

I have a php function I wrote that will take a text file and
I am trying to see what is wrong with a php script a wrote.
I wrote a script in php which reads two files and takes all the
I have a script on my site ('write-review.php') that takes an optional url parameter
I wrote a PHP code like this $site=http://www.google.com; $content = file_get_content($site); echo $content; But
I just wrote a PHP login script, and what I'm trying to accomplish is
I wrote a PHP script. When i try to use it throws an error.
I have a script called notify_me.php which I run like so: script type=text/javascript> //Run
I've written a PHP script that makes a request to a search engine, accesses
I'm trying to write a simple, full text search with PHP and PDO. I'm

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.