Re: [PHP] Matching strings in a flat/text file?

2001-10-23 Thread Pavel Jartsev

Nick Richardson wrote:
 
 ...

 Example: I want to pass a string using the URL (blah.php?car=civic_si) then
 search for ##civic_si in the text file, and print everything until it finds
 ##end.  So the text file will look like this:
 
 ##civic_si
 This is my content, blah blah
 ##end
 
 ##nissan
 This is more content... yadda yadda
 ##end
 
 ...


Try this little code snippet:

?
$filename = 'cars.data';
$car = $HTTP_GET_VARS['car'];
if ($car != '') {
 $file = file($filename);
 if (is_array($file)) {
  $read = FALSE;
  foreach ($file as $f) {
   if (!$read  ereg('^##'.$car, $f))
$read = TRUE;
   elseif ($read  ereg('^##end', $f)) {
$read = FALSE;
break;
   } elseif ($read)
$content .= $f;
  }
 }
}
echo content=$contentbr;
?


Hope this helps. :)

-- 
Pavel a.k.a. Papi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




SV: [PHP] Matching strings in a flat/text file?

2001-10-23 Thread anders nawroth

Why not use RegEx?

I'm doing a similar search with RegEx.
Makes the code much shorter.

Anders Nawroth
www.nawroth.com


- Ursprungligt meddelande - 
Från: Jack Dempsey [EMAIL PROTECTED]
Till: [EMAIL PROTECTED]; Nick Richardson [EMAIL PROTECTED]
Skickat: den 23 oktober 2001 07:20
Ämne: RE: [PHP] Matching strings in a flat/text file?


lots of ideas nick, but can you use a database? MySQL is free and i've found
its almost always better to use databases when you can...
if you can't, you could do something like this:
1. find the pos of the string you need using strpos
2. find the pos of the ending delimiter
3. substr from the first pos to the end (you'll need to add/subtract some
strlen's to slice off the delimiters as well...

jack

-Original Message-
From: Nick Richardson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 23, 2001 1:10 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Matching strings in a flat/text file?


Hey everyone,

Anyone out there know how i could do this:

I have a client who is an import car tuner.  They would like to feature the
cars they work on in their website.  Instead of creating a new .html or .php
file for every car they add to include the background setup, and the general
content (type of car, owner, etc...) i want to put the information in to
text file and search for it in there.

So that's where i need help.  I want to be able to put the info into a text
file and pass the string to search for through the URL, then match
everything between that line and an ending line in the text file, and print
that out to the browser.

Example: I want to pass a string using the URL (blah.php?car=civic_si) then
search for ##civic_si in the text file, and print everything until it finds
##end.  So the text file will look like this:

##civic_si
This is my content, blah blah
##end

##nissan
This is more content... yadda yadda
##end

Any ideas on how i can do this???

//Nick Richardson
[EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Matching strings in a flat/text file?

2001-10-23 Thread Mark

On Mon, 22 Oct 2001 22:09:56 -0700, Nick Richardson wrote:
Hey everyone,

Anyone out there know how i could do this:

I have a client who is an import car tuner.  They would like to
feature the
cars they work on in their website.  Instead of creating a new .html
or .php
file for every car they add to include the background setup, and the
general
content (type of car, owner, etc...) i want to put the information
in to
text file and search for it in there.

So that's where i need help.  I want to be able to put the info into
a text
file and pass the string to search for through the URL, then match
everything between that line and an ending line in the text file,
and print
that out to the browser.

Example: I want to pass a string using the URL
(blah.php?car=civic_si) then
search for ##civic_si in the text file, and print everything until
it finds
##end.  So the text file will look like this:

##civic_si
This is my content, blah blah
##end

##nissan
This is more content... yadda yadda
##end

Any ideas on how i can do this???

the easiest way would be with sed:
$data=`sed -n '/##civic_si/,/##end/p' $filename`



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Matching strings in a flat/text file?

2001-10-22 Thread Nick Richardson

Hey everyone,

Anyone out there know how i could do this:

I have a client who is an import car tuner.  They would like to feature the
cars they work on in their website.  Instead of creating a new .html or .php
file for every car they add to include the background setup, and the general
content (type of car, owner, etc...) i want to put the information in to
text file and search for it in there.

So that's where i need help.  I want to be able to put the info into a text
file and pass the string to search for through the URL, then match
everything between that line and an ending line in the text file, and print
that out to the browser.

Example: I want to pass a string using the URL (blah.php?car=civic_si) then
search for ##civic_si in the text file, and print everything until it finds
##end.  So the text file will look like this:

##civic_si
This is my content, blah blah
##end

##nissan
This is more content... yadda yadda
##end

Any ideas on how i can do this???

//Nick Richardson
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Matching strings in a flat/text file?

2001-10-22 Thread Jack Dempsey

lots of ideas nick, but can you use a database? MySQL is free and i've found
its almost always better to use databases when you can...
if you can't, you could do something like this:
1. find the pos of the string you need using strpos
2. find the pos of the ending delimiter
3. substr from the first pos to the end (you'll need to add/subtract some
strlen's to slice off the delimiters as well...

jack

-Original Message-
From: Nick Richardson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 23, 2001 1:10 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Matching strings in a flat/text file?


Hey everyone,

Anyone out there know how i could do this:

I have a client who is an import car tuner.  They would like to feature the
cars they work on in their website.  Instead of creating a new .html or .php
file for every car they add to include the background setup, and the general
content (type of car, owner, etc...) i want to put the information in to
text file and search for it in there.

So that's where i need help.  I want to be able to put the info into a text
file and pass the string to search for through the URL, then match
everything between that line and an ending line in the text file, and print
that out to the browser.

Example: I want to pass a string using the URL (blah.php?car=civic_si) then
search for ##civic_si in the text file, and print everything until it finds
##end.  So the text file will look like this:

##civic_si
This is my content, blah blah
##end

##nissan
This is more content... yadda yadda
##end

Any ideas on how i can do this???

//Nick Richardson
[EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Matching strings in a flat/text file?

2001-10-22 Thread Nick Richardson

Jack, thanks for the response:

I can use a database if really really needed.  The main reason for wanting
to use a flat file is for ease of update from the client's side.  They are
not technical in the least, and this will save me from having to update a
database everytime.

Although i guess i could write a front end to let them add stuff to the
database... but i'm lazy like that ;).

To do the 3 things you suggested, can you give me a code snippet to do that?

//Nick

-Original Message-
From: Jack Dempsey [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 22, 2001 10:20 PM
To: [EMAIL PROTECTED]; Nick Richardson
Subject: RE: [PHP] Matching strings in a flat/text file?


lots of ideas nick, but can you use a database? MySQL is free and i've found
its almost always better to use databases when you can...
if you can't, you could do something like this:
1. find the pos of the string you need using strpos
2. find the pos of the ending delimiter
3. substr from the first pos to the end (you'll need to add/subtract some
strlen's to slice off the delimiters as well...

jack

-Original Message-
From: Nick Richardson [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 23, 2001 1:10 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Matching strings in a flat/text file?


Hey everyone,

Anyone out there know how i could do this:

I have a client who is an import car tuner.  They would like to feature the
cars they work on in their website.  Instead of creating a new .html or .php
file for every car they add to include the background setup, and the general
content (type of car, owner, etc...) i want to put the information in to
text file and search for it in there.

So that's where i need help.  I want to be able to put the info into a text
file and pass the string to search for through the URL, then match
everything between that line and an ending line in the text file, and print
that out to the browser.

Example: I want to pass a string using the URL (blah.php?car=civic_si) then
search for ##civic_si in the text file, and print everything until it finds
##end.  So the text file will look like this:

##civic_si
This is my content, blah blah
##end

##nissan
This is more content... yadda yadda
##end

Any ideas on how i can do this???

//Nick Richardson
[EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]