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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:42:11+00:00 2026-05-30T23:42:11+00:00

I’m working on a PHP search script that scans a text file repository of

  • 0

I’m working on a PHP search script that scans a text file repository of packages on a website and returns the URL of each match. The text files looks as followed:

PACKAGE NAME: package_one
PACKAGE LOCATION: ./package_one
PACKAGE VERSION: 0.1.2

PACKAGE NAME: package_two
PACKAGE LOCATION: ./package_two
PACKAGE VERSION: 0.2.1

PACKAGE NAME: package_three
PACKAGE LOCATION: ./package_three
PACKAGE VERSION: 1.3.4

PACKAGE NAME: package_one
PACKAGE LOCATION: ./package_one
PACKAGE VERSION: 0.1.2

My search script currently looks as followed:

<?
$search = $_POST['search']; //Passed from a user input form

$data_file = file('http://www.example.com/data_file.txt'); //The text file repository

    $final_concatenated_results = "";

    for ($i = 0, $found = FALSE; isset($data_file[$i]); $i++) {
        if (trim($data_file[$i]) === $search) { 
        $cleanse = trim($data_file[++$i]);
        $output_part_one = strstr($cleanse, '.');
        $output_part_two = "http://www.example.com/packages_repository/".$output_part_one;
        $add_this = "<a href='$output_part_two'>$output_part_two</a>"."<br/>";
        $found = TRUE;
        $final_concatenated_results.=$add_this;
    } }

    if ($found == TRUE) {
        echo $final_results;
    }

    if ($found == FALSE) {
        echo "Error, package not found.";
    }
?>

For example, if “PACKAGE NAME: package_two” were typed in verbatim this would be the output — http://www.example.com/packages_repository/./package_one which works fine.

Ideally, I’d like to know how to change my code so instead of typing in “PACKAGE NAME: package_two”, one could simply type in “package_two” or even some like “two” or “tw”. How much tweaking would that need?

Also, I made a variable to concatenate all of the resulting URLs to one string, so if “package_one” were searched, it would return two URLS… I don’t think I did the code right as it only produces the one URL.

** I should mention that immediately after the package name is matched, it finds the next string following “PACKAGE LOCATION: .” to grab the URL

Any input is appreciated, 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-30T23:42:13+00:00Added an answer on May 30, 2026 at 11:42 pm

    Here you are looking for an exact match:

    if (trim($data_file[$i]) === $search) { 
    

    You can use stripos to see if your search string appears in the line:

    if (stripos($data_file[$i], $search) !== FALSE) {
    

    Note that you need the !== comparison because stripos can evaluate to 0.

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

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.