I wrote this php function to dynamically insert the default date in a drop down option tag. In my function called pickDate I echo out the string at the end with double quotes. Then later in my code I have a for loop that produces a new string and inside the string I am trying to call my function.
My problem is that when I call pickDate()
in my string it is rendering out pickdate()
(literally) and not the result of the function. Looking at my code, my question is : how do I call a function within a string surrounded by double quotes.
Here is what my function looks like:
<?php
function pickDate() {
$dayArray=array();
global $month;
global $day;
$monthArray=array();
$d=1;
$monthArray=array('January','February','March','April','May','June','July','August','September','October','November','December');
$monthOption .="<select name='month'>";
for($i=0; $i<31; $i++){
array_push($dayArray, "$d");
$d++;
}
for($i=0; $i<12; $i++){
$selected="";
if ($month == "$monthArray[$i]") {
$selected="selected='selected'";
}
$monthOption .="<option value='$monthArray[$i]'
$selected>$monthArray[$i] </option>";
}
$monthOption.="</select> <select name='day'>";
for($i=0; $i<31; $i++){
$selected="";
if ($day == "$dayArray[$i]") {
$selected="selected='selected'";
}
$monthOption .="<option value='$dayArray[$i]'$selected>$dayArray[$i] </option>";
}
$monthOption.="</select>";
echo "$monthOption";
}//end function
?>
My function works fine. I want to know how I can call it in the string in this for loop below:
<?php
$xml = simplexml_load_file("gallery.xml");
$c1=count($xml->Picture);
for($i=0; $i<$c1; $i++){
$month =(string)$xml->Picture[$i]->picDate->month;
$day =(string)$xml->Picture[$i]->picDate->day;
$year =(string)$xml->Picture[$i]->picDate->year;
$displayFolder .="<form action='gallery.php' enctype='multipart/form-data' method='post' name='editPic'
id='editPic'><tr><td>
pickDate()
<input type ='text' name='year' size='4'maxlength='4'
value='$year'/></form></td> </tr>";
}
?>
then I output the displayfolder string in a html table below:
<table border= "1px"><tr><td><?php
print"$displayFolder";?></table>
So the problem again is calling the pickDate function cause it is in a string and I would like to know how I can out put the pickDate()
result in the table. I like how it is all surrounded by double quotes. Can someone please tell me how to call the function properly in the string without having to change my string to much.