Getting certain values from a text file with PHP?

Associate
Joined
29 Dec 2004
Posts
2,253
Let's say i have a text file containing values like this:

* 01/01/2001 - 05/01/2001 Test Text
* 31/12/2004 - 01/01/2005 More Tests
* 04/05/2008 - 02/06/2008 Hello again
* 01/10/2008 - 03/10/2008 Testypie

..could i use PHP to display a page that would display anything in the text file where the dates were, say, a month ahead of the first date listed (when i say first, i mean the first of the two..e.g. 04/05/2008 on the third line)? For example, if i were to view the PHP page now, it would output "01/10/2008 - 03/10/2008 Testypie".

I have Googled around a bit, and can find everything i could ever want to do with a text file...bar sorting it! Any help much appreciated.
 
Do you have any example code i could use? I know how to open and write to files like i mentioned but am not sure how to search through for certain values etc...
 
Thanks guys, i'll have a look around. The text fragment is exactly the same as the format i'm using, which unfortunately cannot be changed as it is used for a PHP app that displays a Calendar in Dokuwiki.
 
Another quick one:

If i have a text file with this content:

AA - Mr Test0, The House0, 10 House Road, Testerton, London, AA1 1AA.
AA - Mr Test1, The House1, 11 House Road, Testville, London, AA1 1AA.
AB - Mr Test2, The House2, 12 House Road, Testtown, London, AA1 1AA.
AB - Mr Test3, The House2, 13 House Road, Testingtontown, London, AA1 1AA.

And i currently get "Mr Test0", "Mr Test1"...etc with:

Code:
$TheSite = $_POST['address'];
	$TheSite = substr($TheSite,strpos($TheSite,'-')+1);
		$TheSite = substr($TheSite,0,strpos($TheSite,','));
	$TheSite = trim($TheSite);
$StartDate = $_POST["startdate"];

How can i adapt that so i can output
"Mr Test0, The House0"
"Mr Test1, The House1"

etc, rather than

"Mr Test0"
"Mr Test1"

...?
 
Last edited:
Ah it's alright, it's all working as is (and i'm not sure how to re-write it) so i'm just looking for how to tweak the substr bit to make it work by going to the next comma...
 
Sorry guys i don't need an array, i'm only getting the $_POST['address'] value which is in the format of "AA - Mr Test0, The House0, TestTown..." etc and i just want to format it so it only contains the value "Mr Test0, The House0".

I think i just need to amend the substr bit to go between the hyphen "-" and the second comma (after "The House0") rather than between the hyphen and the first comma (after "Mr Test0".)

Thanks
 
Sorry i think it's this bit i need to change:

Code:
strpos($TheSite,',')

I need it to get the second comma, not the first one from a sentence like this:

AA - A test, Test house, Test Town, West Testy, UK

Can anyone help? Is this do-able?
 
Afraid not, i'm basically just integrating my very very simple script with something much bigger. Thanks for the above! I guess it's not possible with strpos...
 
Back
Top Bottom