rei
-
Posts
8 -
Joined
-
Last visited
Never
Posts posted by rei
-
-
i just have no idea on how to make the application with button "Print" so that users can print out the page by clicking the button.
any idea or hints for me please?
thanks
-
thanks ifa and redarrow
found one way.
put all the dates in an array
sort it
and get the first and last element :) -
is there anyway i can compare 3 or more date type column?
let's say i have
------------------------------------------------
date1 | date2 | date3
------------------------------------------------
2006-06-01 | 2006-06-15 | 2006-09-19
------------------------------------------------
and my select statement returns this 3 value.
is there any way i can write in PHP to get the earliest or the latest date?
let's say:
[code]
$earliest = XXX($row[date1], $row[date2], $row[date3]) <- returns ("2006-06-01")
$latest = XXX($row[date1], $row[date2], $row[date3]) <- returns ("2006-09-19")
[/code]
i tried to get these from mysql command like if possible but cant find any way to do it..
i guess there's no function to this..
select XXXXX(date1,date2,date3) <--returns '2006-06-01 '
select YYYYY(date1,date2,date3) <--returns '2006-09-19 -
Shogun,
thanks!! -
tomfmason,
thanks but how to write to a specific line is still unanswered
[quote author=tomfmason link=topic=100146.msg394901#msg394901 date=1152589789]
This somewhat answers my question at [url=http://www.phpfreaks.com/forums/index.php/topic,100138.0.html]http://www.phpfreaks.com/forums/index.php/topic,100138.0.html[/url]. How would I specify then line number.
[/quote] -
willfitch,
thanks for the reply
but i still get the result as following
[quote]
apple1
orange2
lime3
strawberry4
newlinele5
mango6
[/quote]
my code is as following:
[code]
<?php
$file = file("data/file.txt");
foreach($file as $line_number => $contents){
if(trim($contents) == 'strawberry'){
fputs($fp, "newline");
}
}
?>
[/code]
is it that fputs isnt a good idea?
[quote author=willfitch link=topic=100146.msg394895#msg394895 date=1152589232]
Well,
If you are hard-coding your parameters with your if conditions, you could use file() and do a foreach() loop and loop through each line. Once you hit the strawberry, insert your new line.
[code=php:0]
<?php
$file = file('file.txt');
foreach($file as $line_number => $content) {
if (trim($content) == 'strawberry') {
// do your thing here.
}
}
?>
[/code]
[/quote] -
i have a file with the contents of :
[quote]
apple1
orange2
lime3
strawberry4
pineapple5
mango6
[/quote]
i would like to insert one newline "newline" in between "lime3" and "strawberry4"
first i wrote my code like this:
[code]
<?php
$fp = fopen("data/file.txt", "r+");
while($buf = fgets($fp)){
if(preg_match("/strawberry/", $buf)){
fputs($fp, "newline\n");
}
}
?>
[/code]
but it ended up like this:
[quote]
apple1
orange2
lime3
strawberry4
newline
e5
mango6
[/quote]
so i changed my code to the following (omitting \n at the end of "newline")
[code]
<?php
$fp = fopen("data/file.txt", "r+");
while($buf = fgets($fp)){
if(preg_match("/strawberry/", $buf)){
fputs($fp, "newline");
}
}
?>
[/code]
but i got the result of
[quote]
apple1
orange2
lime3
strawberry4
newlinele5
mango6
[/quote]
i cant seem to have a line inserted in between..
it replaces the line after it..
i would appreciate any help
thanks
Reading contents from file but substitute variable wth value
in PHP Coding Help
Posted
I am trying to write a PHP application where an automatic response is sent out after form is posted.
The contents of the email was to be read from a file, but I would like to exchange the variable in the file to the actual value of it.
For example, there is a <form> and my user posted his name as "Andy".
I would like my automatic response email to be appear like the following where the name is the value which the user posted.
-----------------------
Dear Andy,
Thank you for posting.
We will contact you soon.
-----------------------
However i just get the following result: ???
-----------------------
Dear $name,
Thank you for posting.
We will contact you soon.
-----------------------
Could anyone tells me what's wrong with my code?
My function looks like this:
PHP Program
data.txt
Thank you