I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?
Thanks!
Bill
Passing data back to .html file
Moderator: General Moderators
You need to use JS for this purpose. Some code I wrote in quickly:
You can find tutorial about JS in: http://www.w3schools.com/js/default.asp
Code: Select all
<script type="text/javascript">
var temp = location.search;
var idx2_data1;
var idx2_data2;
if(temp)
{
var idx1_data1 = temp.indexOf("?data1=");
var idx1_data2 = temp.indexOf("&data2=");
if ((idx1_data2 >= 0)&&(idx1_data1 >= 0))
{
//The size of idx1_data1
idx1_data1 += 7;
//The size of idx1_data2
idx1_data2 += 7;
var idx2_data2 = temp.indexOf("&", idx1_data2);
var idx2_data1 = temp.indexOf("&", idx1_data1);
if (idx2_data2 > 0) { data2 = temp.substring(idx1_data2, idx2_data2); } else { data2 = temp.substring(idx1_data2); }
if (idx2_data1 > 0) { data1 = temp.substring(idx1_data1, idx2_data1); } else { data1 = temp.substring(idx1_data1); }
}
}
document.writeln('<font color="#cc0000"><b>Data1:</b></font> '+data1);
document.writeln('<font color="#cc0000"><b>Data2:</b></font> '+data2);
</script>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Passing data back to .html file
This does not require the use of Javascript at all. Use the PHP filesystem functions mixed with what you already know about displaying data to the screen.wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?
Thanks!
Bill
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Passing data back to .html file
Why not have php process both pages?wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?
Thanks!
Bill
Re: Passing data back to .html file
I have done that and all works great. I just thought there should be a way to do it as described and if there is a way (without JS) then I should learn about it.Jcart wrote:Why not have php process both pages?wep wrote:I have a site already written with html. Now that I've learned some php I want to open a data file with php code, read in the text and pass it back to the calling website to display it. I've been able to easily send data from forms, text boxes etc. to a php program but not the other way round. Any help?
Thanks!
Bill
Thanks a lot for responding.
Bill