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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:42:09+00:00 2026-06-09T00:42:09+00:00

I’m working on a test site that presents real estate like information on a

  • 0

I’m working on a test site that presents real estate like information on a search. Alongside images of the houses there are descriptions brought in through directory access. I have all the lines working correctly, except for the “Description:” line. In the text files each category is separated by line, except the “Description:” category runs after the title line and into multiple lines up to the end of the file. I am using a concatenated fgets to get the info, but in my results the output is showing the complete house information correctly including the “Description:” line, but on each following result the house information repeats what it previously printed and then the rest of the next file. If I get rid of the concatenation and just do a regular:

$pos = stripos($line, 'Description:');

if($pos !== false)
{
$description = substr($line, 12);
$description = trim($description);
}

Then I end up with only the “Description:” printing without the text of the description section.

This is an example of the imported text file:

City: OceanCove
Price: $950,000

Bedrooms: 5
Baths: 3
Footage: 3000 sq. ft.
Realtor: Shirley Urkiddeng
Grabber: Fantastic Home with a Fantastic View!
Description:

You will never get tired of watching the sunset
from your living room sofa or the sunrise
from your back porch with a view overlooking
the gorgeous coral canyon. Once in a lifetime
opportunity!

Here is my code (in the “Description” section there is some commented out other trials that I did:

     <?php
$findhome = $_POST['findhome'];

$header = getHeader($findhome);
print $header;

getResults($findhome);

    function getHeader($findhome)
    {
if (empty($findhome))
    {
        $header = "<h3>Current Listings: <br />";
    }
    else
    {
        $header = "<h3>Current Listings that match: $findhome </h3><br />";
    }

    return $header;

    }

    function getResults($findhome)
    { 


if (empty($findhome))
{
    $findhome ='ALL';
}

$dirname = 'images';

$dirhandle = opendir($dirname);

if ($dirhandle)
{
    $houseimagesarray = array();

    while (false !== ($file = readdir($dirhandle)))
    {
        if ($file !='.' && $file !='..')
        {
            $first_6 = substr($file,0,6);

            if($first_6 =='house_')
            {
                array_push($houseimagesarray, $file);
            }
        }
    }
}

sort($houseimagesarray);

    $description = '';

foreach ($houseimagesarray as $image_filename)
{


//***************************************************
//** Function Definitions
//***************************************************

    //Get Image Files

            $imagename ='images/'.$image_filename; //.jpg files
            $house_img = "<p><img src='".$imagename."'></p>";

            $houseinfo_filename = str_replace ('.jpg', '.txt',           $image_filename);

            $filename = 'data/'.$houseinfo_filename; //.txt file

            $fp = fopen($filename, 'r');


    //Get Image House Information


    $show_house = 'Y';  //Set default value

    while(true)
    {
        $line = fgets($fp);

        if (feof($fp))
        {
            break;
        }

        $pos = stripos($line, 'City:');

        if ($pos !== false)
        {
            $city = substr($line, 5);
            $city = trim($city);

            if ($findhome != 'ALL')
            {
                $subpos = stripos($city, $findhome);

                if($subpos === false)
                {
                    $show_house = 'N';
                    break;
                }
            }
        }

        $pos = stripos($line, 'Price:');

        if ($pos !==false)
        {
            $price = substr($line, 6);
            $price = trim($price);
        }

        $pos = stripos($line, 'Bedrooms:');

        if ($pos !== false)
        {
            $bedrooms = substr($line, 9);
            $bedrooms = trim($bedrooms);
        }

        $pos = stripos($line, 'Baths:');

        if ($pos !== false)
        {
            $baths = substr($line, 6);
            $baths = trim($baths);
        }

        $pos = stripos($line, 'Footage:');

        if($pos !== false)
        {
            $footage = substr($line, 8);
            $footage = trim($footage);
        }

        $pos = stripos($line, 'Realtor:');

        if($pos !== false)
        {
            $realtor = substr($line, 8);
            $realtor = trim($realtor);
        }

        $pos = stripos($line, 'Grabber:');

        if($pos !== false)
        {
            $grabber = substr($line, 8);
            $grabber = trim($grabber);
        }

        $pos = stripos($line, 'Description:');

        if($pos !== false)
        {
            $descriptionFlag = "Y";
        }
        if($descriptionFlag=='Y')
        {
            $description .=$line."<br />\n";
            //$description =$line."<br />";
            //$description = $description.$line."<br />";
        } 
    }

    if ($show_house == 'Y')
    {
        print $house_img;

        print "<h3>".$grabber."</h3><br />";
        print "City: ".$city."<br />";
        print "Bedrooms: ".$bedrooms."<br />";
        print "Baths: ".$baths."<br />";
        print "Price: ".$price."<br />";
        print "Footage: ".$footage."<br />";
        print "Realtor: ".$realtor."<br />";

        print $description;

      }


      }
     }  
    ?>

New Code:

    $pos = stripos($line, 'Description:');

        if($pos !== false)
        {
            $descriptionFlag = "Y";
        }
        if($descriptionFlag=='Y')
        {
            if(!feof($fp))
            {
                $description .=$line."<br />\n";

                if(feof($fp))
                {
                    break;
                }

            }
        }
  • 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-06-09T00:42:11+00:00Added an answer on June 9, 2026 at 12:42 am

    Since Description may contain more than one line, you have to loop over the lines until you’re done with the Description field. If you have multiple items in the same file you’ll probably want to search for the next City in order to bail-out. Something like:

    if($descriptionFlag=='Y') {
      while ($line = fgets($handle, 8192)) {
          $line = trim($line);
          if($line === 'City')
            break;
          $description = $description . " " . $line;
      }
      $description = $description . "<br />\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
This could be a duplicate question, but I have no idea what search terms

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.