Page 1 of 1

Need a very simple PHP script.

Posted: Sun Apr 05, 2009 5:45 am
by harrytheshark
Hi there,
I'm a cocoa developer and for one of my apps I need to do some server side coding. Problem is, I've no experience with PHP at all.
What I need isn't very complicated (I don't think).
Basically I need to be able to post 2 strings to my website, and then have a page on the site display them.
They need to be saved until 2 other strings are posted to replace them.

For example, if I post "string1" and "string2" to "theFile.php", I would then like a file called "displayTheStrings.html" to just show them in the body of the page. They need to be saved so I can view them when I need to, but then If I post two more strings, the old ones are replaced.

Thanks,
Tom.

Re: Need a very simple PHP script.

Posted: Sun Apr 05, 2009 7:04 am
by greyhoundcode
Something along these lines?

Code: Select all

<?php
// "theFile.php"
 
$string1 = $_POST['string1'];  // You may wish to carry out some kind
$string2 = $_POST['string2'];  // of validation here, depending on what
                               // you are doing this for
 
// Place the strings amongst some HTML
 
$output = <<<HTML
<html>
<head><title> Display the Strings </title></head>
<body> $string1 $string2 </body>
</html>
HTML;
 
// Spit it out as a static file
 
file_put_contents('displayTheStrings.html', $output);
?>

Re: Need a very simple PHP script.

Posted: Sun Apr 05, 2009 7:41 am
by harrytheshark
Yeah that's perfect!
Thanks for the help,
Tom.