mahirharoon 0 Report post Posted December 6, 2007 i don't think i wrote a good topic titlehow to do this:on a page with a text box and a buttonwhen the user writes what page he wants into the textboxand clicks the buttonit looks for the file and create it with a php extensionand adds it to the page switcherand case is added by putting the same querywhthout the extensionexampleif the code of the page switcher is <?php $variable = $_GET['id'];switch($variable) {default: include('home.php'); break;case "guestbook": include('guestbook.php'); break;}?>the user writes forum.phpthen the code will become<?php $variable = $_GET['id'];switch($variable) {default: include('home.php'); break;case "guestbook": include('guestbook.php'); break;case "forum": include('forum.php'); break;}?> Share this post Link to post Share on other sites
sonesay 7 Report post Posted December 6, 2007 Im sorry but your not very clear please rewrite it so we can understand better what you are trying to do exactly. I got the part about you wanting to have an input text box and button for submitting. it looks for the file and create it with a php extensionI dont know what you want to do here exactly. Create a whole new php file? or just add the entry to your case switch. Share this post Link to post Share on other sites
shadowx 0 Report post Posted December 6, 2007 Well to create the php file is easy enough, just google the FREAD, FOPEN and FWRITE functions and that will tell you how to search for and create a fileAs for editing that php file... well the best way to do it would be to use FREAD to read the contents of the page switcher into a variable, and then search that variable fr the end of the switch function EG: switch($variable) {default: include('home.php'); break;case "guestbook": include('guestbook.php'); break;case "forum": include('forum.php'[color="#FF0000"][i][u][b]); break;}[/b][/u][/i][/color] So your search critera would be "); break;}" you can use "in_str" or a similar string search function to search that new variable for this criteria, this would give you the cursor position of the last bracket "}" in that switch function. From there you could go back a space then add a newline to the file and enter the new line EG "case "profile": include('profile.php'); break;"its a bit confusing i know but it does make sense to me Share this post Link to post Share on other sites
mahirharoon 0 Report post Posted December 7, 2007 Im sorry but your not very clear please rewrite it so we can understand better what you are trying to do exactly. I got the part about you wanting to have an input text box and button for submitting.I dont know what you want to do here exactly. Create a whole new php file? or just add the entry to your case switch.it looks for the php file and will create it if it is not in the directory specifiedand adds the entry to case switch Share this post Link to post Share on other sites
gogoily 0 Report post Posted December 11, 2007 You should use function "file_exists('filepath')" if you wanna check whether the PHP file created or not Share this post Link to post Share on other sites
mahirharoon 0 Report post Posted December 15, 2007 i wrote the code for writing into the switch <?php$filename = 'index.php';if (is_writable($filename)) { echo 'The file is writable';} else { echo 'The file is not writable';}if (is_writable($filename)) {$filename = 'index.php';$somecontent = "the code.....";// Let's make sure the file exists and is writable first.if (is_writable($filename)) { if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "\n Success, wrote ($somecontent) to file ($filename)"; fclose($handle);} else { echo "\n The file $filename is not writable";}; }?> Share this post Link to post Share on other sites
mahirharoon 0 Report post Posted December 15, 2007 (edited) sorry for double posti also wrote the code for opening it and creating it if not extisting <?php$handle = fopen("index.php", "a+");?>EDIT:the main problem is it will be inserted after define tag (<?php?>) Edited December 22, 2007 by mahirharoon (see edit history) Share this post Link to post Share on other sites