PHP - Create Php Code Which Convert Words And Save Into File - Need Help
Hello,
I am novice in PHP, I read book and try to write some PHP code, but I don't have success in that my attempt. Do someone can to help me? I think that this what I work isn't hard, but I don't know to do. I need to create in PHP some code which will: 1. In text field I enter some words in 2-3 rows, example word11 word12 word13 word21 word22 word23 word31 word32 word33 and click to button Convert, 2. After click on that button php script will take that words and convert into this mode: word11-word12-word13(TAB here without space)word11 word12 word23 word21-word22-word23(TAB here without space)word21 word22 word23 word31-word32-word33(TAB here without space)word31 word32 word33 (spaces between words will convert into - and between first and second mode with TAB) 3. On that way converted text to be saved into new file which will be with name of first line "word11 word12 word13". I know procedure to make this, but I don't know syntax very well Can someone write me code or part of code, to give me idea how I to make this? Thank you very much, Mladen Similar TutorialsHello, i need some help/info about searching words in files (txt or xml) and saving them to db or another file.
For example ive got an xml file like below:
<families>
<family>
<name>brown</name>
<city>denver</city>
<members>12</members>
</family>
<family>
<name>jackson</name>
<city>new york</city>
<members>6</members>
</family>
</families>
i want to search for: <family> then save the lines till it comes to the word </family> and then goes to the next group. did some reading about array, preg_match, strpos functions but dont know where to start. what is the best way to do this?
can you guys give me some advise... or links to good tutorials?
thanks in advance!
Hey guys! I have the following script to create an excel file, the thing is that I dont want to be asked if I want to open or save the file when accessing the php file...I just want the php file directly to save the excel file. Heres the code: $filename = "test.xls"; $contents = "testdata1 \ntestdata2 \ntestdata3 \n"; header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename='.$filename); echo $contents; Is there a way instead of using the header function, use something like: fopen, fwrite, fclose ? Thanks in advance! Cheers, I have this code header("Content-type: text/xml"); $database = "rprice"; $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); $query = "SELECT * FROM plist ORDER BY date DESC"; $resultID = mysql_query($query, $linkID) or die("Data not found."); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<graph>\n"; for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "\t<set date =\"" . $row['date'] . "\" value =\"" . $row['sprice'] . "\">\n"; $xml_output .= "\t</set>\n"; } $xml_output .= "</graph>"; echo $xml_output; I want to save this xml file into the folder name Data what is the code of that please help Hello Friends, I need to convert the DOC (WordFile) in to PDF through PHP code in my web. According to requirement whenever the user upload the .Doc file code should convert that .Doc file into .PDF file at runtime. I have tried by using PDFLib and FPDF functions but when the .Doc file contains the images,tables etc. either FPDF or PdfLib being falied to generate PDF file I am using Linux-PHP-MySQL Technolgoies for development. I am expecting suggestions and help from expert friends who can help me out to achive this. Thanks! HI All, I have a form submission that uploads a photo as well as submitting other data. I would like to change the name of the photo to the id of the person record (created automatically on by the database) then a hyphen, then their first name and lastname. (i am flexible on this). This file name will also need to be submitted into the person record so the photo and the person can be linked. I am struggling with this one - but here is the code i have so far.
<?php include 'includes/dbconn.php'; $target_dir = "img/people/"; $target_file = $target_dir . basename($_FILES["personHeadshot"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); if ($_SERVER['REQUEST_METHOD']=='POST'){ $fn = $_POST['fname']; $ln = $_POST['lname']; $ad1 = $_POST['ad1']; $ad2 = $_POST['ad2']; $city = $_POST['city']; $post = $_POST['postcode']; $tel = $_POST['phone']; $email = $_POST['email']; $crole = $_POST['comRole']; $OFA = $_POST['OFA']; $playerType = $_POST['playerType']; $team = $_POST['primaryTeam']; $stmt = $conn->prepare(" INSERT IGNORE INTO person (fname, lname, committee_role_id, player_type_id, team_id, ad1, ad2, city, postcode, mobile, email, on_field_auth_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) "); $stmt -> bind_param(ssiiissssssi, $fn, $ln, $crole, $playerType, $team, $ad1, $ad2, $city, $post, $tel, $email, $OFA); $stmt -> execute(); // Check if image file is a actual image or fake image //photo upload $check = getimagesize($_FILES["personHeadshot"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } //photo upload header("location: ../admin-people-list.php"); } // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["personHeadshot"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["personHeadshot"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["personHeadshot"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } }
Hello, all: been trying to convert this little single-file upload to multiple by naming each file form-field as "userfile[]" as it's supposed to automatically treat them as an array.. but no luck! Can you guide me as to what am I doing wrong?? appreciate the help! Code: [Select] <?php if (!isset($_REQUEST["seenform"])) { ?> <form enctype="multipart/form-data" action="#" method="post"> Upload file: <input name="userfile[]" type="file" id="userfile[]"> Upload file: <input name="userfile[]" type="file" id="userfile[]"> <input type="submit" value="Upload"> <input type="hidden" name="seenform"> </form> <?php } else { // upload begins $userfiles = array($_FILES['userfile']); foreach ($userfiles as $userfile) { // foreach begins $uploaded_dir = "uploads/"; $userfile = $_FILES['userfile']["name"]; $path = $uploaded_dir . $userfile; if (move_uploaded_file($_FILES['userfile']["tmp_name"], $path)) { print "$userfile file moved"; // do something with the file here } else { print "Move failed"; } } // foreach ends } // upload ends ?> Hi, i have tried everything i can think of to get this to work correctly. What is below here, is what i have last tried to work with..: basically the script allows the use to register an email account on a cpanel domain. Everything works perfectly but then i added a option for banned words now i cant get the script to work.. basically what happens is: the user creates an email account, if the account is not a banned word and does not exist, then the message echoes success, and the $_Post values are also entered into the database under the users name. and the email is also created with the $f fopen if success the email form also does not show.. so only one email per user.. i just cant get it to work with the banned words included.. what to note:: this is a function in a function.. $bannedemailwords='customerinformation,custinfo,customerinfo,custtext,custsupport,customersupport,admin,accounts'; $bannedmail=explode(',', $bannedemailwords); $bannedmail = array_unique($bannedmail); sort($bannedmail); foreach($bannedmail as $noemail) //the selected username if ($Config['enablemyemailapp_enable'] == '0' && $_POST['cfg_enablemyemailappaddress_enable'] !== $noemaill && $_POST['cfg_enablemyemailappaddressdomain_enable'] !== 'Select a domain'){ $cpuser = 'ausername'; $cppass = 'apassword'; $cpdomain = 'adomain'; $cpskin = 'askin'; $epass = 'somepassword'; $equota = 'somequota'; $euser = $_POST['cfg_enablemyemailappaddress_enable']; $epass = $_POST['emailspassword_enable']; $edomain = $_POST['cfg_enablemyemailappaddressdomain_enable']; if (!empty($euser) && $euser !=='nomail') while(true) { $f = fopen ("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$euser&domain=$edomain&password=$epass"a=$equota", "r"); if (!$f) { $enablemyemailapp_enable = '0'; $enablemyemailappaddress_enable = 'Replace with a Name'; $enablemyemailappaddressdomain_enable = 'Select a domain'; $msgemail = 'The email '.$euser.'@'.$edomain.' is a restricted email account.'; break; } $enablemyemailapp_enable = '1'; $enablemyemailappaddress_enable = $_POST['cfg_enablemyemailappaddress_enable']; $enablemyemailappaddressdomain_enable = $_POST['cfg_enablemyemailappaddressdomain_enable']; $msgemail ='<center><font color="#ff0033">Your Email '.$euser.'@'.$edomain.' has been created.</font></center>'; while (!feof ($f)) { $line = fgets ($f, 1024); if (ereg ("already exists", $line, $out)) { $enablemyemailapp_enable = '0'; $enablemyemailappaddress_enable = 'Replace with a Name'; $enablemyemailappaddressdomain_enable = 'Select a domain'; $msgemail ='<center><font color="#ff0033">The email account '.$euser.'@'.$edomain.' already exists.</font></center><br><center>Please try again!</center>'; break; } } echo $msgemail; $_POST['cfg_enablemyemailapp_enable']= $enablemyemailapp_enable; $_POST['cfg_enablemyemailappaddress_enable']=$enablemyemailappaddress_enable; $_POST['cfg_enablemyemailappaddressdomain_enable']=$enablemyemailappaddressdomain_enable; @fclose($f); break; } } If you are using Vertabelo for creating database models and you access your database with Propel library, you'll find the following instructions useful. I have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. I want to save files to a directory. I am using a input type="text" to let user paste directory, then they choose the file from an upload form, then press submit. So here is my script: ============== <form method="post" action="" enctype=...> <input type="text" name="textboxDir" /> <input type="file" name="uploadedFile"/> </form> So how do I now save the uploaded file via $_POST['uploadedFile'] to the text box directory: $_POST["textBoxDir"]? Any help much appreciated! Hello, I'm editing an XML file using PHP, the XML file contains a playlist of songs for a flash mp3 player. Now I'm able to edit the XML file, but I'm not able to save it . Here's my code: $random_speed = mt_rand(1,15); // Discspeed $song_title = /*mysql_real_escape_string($_GET['song_title'])*/ "My First XML Edit"; $song_artist = /*mysql_real_escape_string($_GET['song_artits'])*/ "A great author"; $song_filename = /*basename(mysql_real_escape_string($_GET['song_filename']))*/ "myfirstxmledit.mp3"; /* Open image directory and get a random image name */ $dir = "./img"; /* Scan the directory and put everything in an array */ $files = scandir($dir); /* Count the elements in the array */ $count_array = count($files); /* Pick a random index from the array */ $rand_array = array_rand( $files, 1 ); /* Pick the value of the random index */ $random_image = $files[$rand_array]; /* Loop through array and if element is not equal to "." or ".." then set the random_image variable */ if( ($random_image == "." ) || ($random_image == ".." ) ){ while( ($random_image == "." ) || ($random_image == ".." ) ){ $random_image = $files[$rand_array]; } }elseif( ($random_image != "." ) || ($random_image != ".." ) ){ echo $random_image; } /* Open the music.xml file */ $xml = new DOMDocument('1.0', 'utf-8'); $xml->formatOutput = true; $xml->preserveWhiteSpace = false; $xml->load('music.xml'); /* Begin settin new element to music.xml file */ $newItem = $xml->createElement('song'); $newItem->appendChild($xml->createElement('title', "'$song_title'")); $newItem->appendChild($xml->createElement('artist', "'$song_artist'")); $newItem->appendChild($xml->createElement('url', "songs/'$song_filename'")); $newItem->appendChild($xml->createElement('image', "img/'$random_image'")); $newItem->appendChild($xml->createElement('discspeed', $random_speed)); /* Add the new elements to the xml tag 'song' */ $xml->getElementsByTagName('song')->item(0)->appendChild($newItem); /* Save the xml file */ $xml->save(); I've tried to enter the filename in the last $xml->save() function, didn't work, added the location + filename, didn't work ... Anyone knows what or how do I save the file? Thanks! Hello, I want to do, when someone click on button/link will open this: but not Save As, but Open. I know how to make simple form: <html> <body> <form action="edit.php" method="post" enctype="multipart/form-data"> <label for="file">File:</label> <input type="file" name="file" id="file" /> <br><br> <input type="submit" name="submit" value="Open"/> </form> </body> </html> But here You must click Browse, but I want to do like in photo: if You click on button, then at once will open form like photo. Many thanks, Tadas P.S. Sorry for my really bad English. Hi Everyone, i need some help how can i save this jsonfile to the webserver? my code // Load initial values from JSON 'file' jsonfile = '[{"lane 1":"1","lane 2":"1","lane 3":"5","lane 4":"2"}]'; var initialstate = JSON.parse(jsonfile); setLaneState("lane1",initialstate[0]['lane 1']) setLaneState("lane2",initialstate[0]['lane 2']) setLaneState("lane3",initialstate[0]['lane 3']) setLaneState("lane4",initialstate[0]['lane 4'])
Hi, I am trying to save some content with form which has php code in it. i.e $submittedphpcode <?php echo 'test'; ?> my code to save that $submittedphpcode $file = "file.php"; $ourFileHandle = fopen($filefile, 'w+') or die("can't open file"); fwrite($ourFileHandle, "$submittedphpcode"); fclose($ourFileHandle); and i am getting this file created with slashes <?php\r\n\r\necho \'test\';\r\n\r\n?> i tried with stripslashes but it just remove \ not r n , i need to keep spaces etc. any help on how to save it as php file properly? Thanks Hello all. I have a script that exports data from mysql to a csv file. Everything works great. However, I do not know how to save the csv file to the server. Does anyone have any ideas how I would do that? The script is below. Thanks for all help! Code: [Select] <?php $host = 'localhost'; $user = ''; $pass = ''; $db = ''; $table = ''; $file = 'export'; function escape_csv_value($value) { $value = str_replace('"', '""', $value); // First off escape all " and make them "" if(preg_match('/,/', $value) or preg_match("/n/", $value) or preg_match('/"/', $value)) { // Check if I have any commas or new lines return '"'.$value.'"'; // If I have new lines or commas escape them } else { return $value; // If no new lines or commas just return the value } } $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].", "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= escape_csv_value($rowr[$j]).','; //$csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); //header( "Content-Type: application/save-as" ); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: attachment; filename=".$filename.".csv"); //header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?> Hello. Racking my brains here, having trouble with this. Running a sports league, trying to get the output of one variable at a different font color OR insert a simple check mark graphic. Either way I am stuck. I am a bit out of practice here. Here is the code. Where is says echo ( Locked) is where I would like to either have locked in a color, say green or red - or insert check mark symbol. Code: [Select] <?php $last = -1; while($team = mssql_fetch_assoc($res)) { if ($last != $team['l_id']) { $last = $team['l_id']; echo "<br><span class=\"dk_greyTxt\" style=\"font-size: 14px\"><strong>$team[night] night, $team[type] $team[size]s $team[division]</strong></span><br><br>"; } echo "<strong>$team[teamname] - ($team[shirtcolor] shirts)</strong><br> RegDate: $team[reg_start]<br>RegDone: $team[reg_done]"; $cpt = mssql_query("SELECT firstname, lastname, shirtsize, feepaid, feememo FROM captain WHERE c_id = $team[captain]",$conn); $c = mssql_fetch_assoc($cpt); if($team["locked"] == 1) { echo " (Locked)"; } else { echo " "; } echo "<br>"; I want a code to automatically make specific words within my content bold. For example, If the word "car" appears, make that word bold. Thanks How can i handle what the user clicked in the Save File Dialog Box? if(user clicked "save") { i will send them an email; } else if (user clicked "cancel") { i will not send them an email; } is this possible? Please help me out guys. Thankyou Hi Chaps, I'm working on a PHP script to mysqldump database to file. Using this as a base: http://www.edmondscommerce.co.uk/mysql/php-mysql-dump-script/, I've managed to strip it down to this: Code: [Select] set_time_limit(0); $mysql_host='localhost'; $mysql_database='database'; $mysql_username='username'; $mysql_password='pasword'; _mysql_test($mysql_host,$mysql_database, $mysql_username, $mysql_password); $print_form = 0; header('Content-type: text/plain'); header('Content-Disposition: attachment; filename="'.$mysql_database."_".date('Y-m-d').'.sql"'); $filename = $mysql_database."_".date('Y-m-d').'.sql'; _mysqldump($mysql_database); function _mysqldump($mysql_database) { $sql="show tables;"; $result= mysql_query($sql); if( $result) { while( $row= mysql_fetch_row($result)) { _mysqldump_table_structure($row[0]); _mysqldump_table_data($row[0]); } } else { echo "/* no tables in $mysql_database */\n"; } mysql_free_result($result); } function _mysqldump_table_structure($table) { echo "/* Table structure for table `$table` */\n"; echo "DROP TABLE IF EXISTS `$table`;\n\n"; $sql="show create table `$table`; "; $result=mysql_query($sql); if( $result) { if($row= mysql_fetch_assoc($result)) { echo $row['Create Table'].";\n\n"; } } mysql_free_result($result); } function _mysqldump_table_data($table) { $sql="select * from `$table`;"; $result=mysql_query($sql); if( $result) { $num_rows= mysql_num_rows($result); $num_fields= mysql_num_fields($result); if( $num_rows> 0) { echo "/* dumping data for table `$table` */\n"; $field_type=array(); $i=0; while( $i <$num_fields) { $meta= mysql_fetch_field($result, $i); array_push($field_type, $meta->type); $i++; } echo "insert into `$table` values\n"; $index=0; while( $row= mysql_fetch_row($result)) { echo "("; for( $i=0; $i <$num_fields; $i++) { if( is_null( $row[$i])) echo "null"; else { switch( $field_type[$i]) { case 'int': echo $row[$i]; break; case 'string': case 'blob' : default: echo "'".mysql_real_escape_string($row[$i])."'"; } } if( $i <$num_fields-1) echo ","; } echo ")"; if( $index <$num_rows-1) echo ","; else echo ";"; echo "\n"; $index++; } } } mysql_free_result($result); echo "\n"; } function _mysql_test($mysql_host,$mysql_database, $mysql_username, $mysql_password) { global $output_messages; $link = mysql_connect($mysql_host, $mysql_username, $mysql_password); if (!$link) { array_push($output_messages, 'Could not connect: ' . mysql_error()); } else { array_push ($output_messages,"Connected with MySQL server:$mysql_username@$mysql_host successfully"); $db_selected = mysql_select_db($mysql_database, $link); if (!$db_selected) { array_push ($output_messages,'Can\'t use $mysql_database : ' . mysql_error()); } else array_push ($output_messages,"Connected with MySQL database:$mysql_database successfully"); } } The problem is, I want the file to save to a specific network location, rather than the output being sent to headers. I've tried to play around with: Code: [Select] ob_start();.... $page = ob_get_contents(); ob_end_flush(); $fp = fopen("output.html","w"); fwrite($fp,$page); fclose($fp); But this outputs to the browser, then saves the file...I would like to load the page, and have the script create and save the file where I want it (without the output in the browser, or prompt to save/download file). Note: I need something like this as I'm running PHP/MySQL on IIS, so can use shell/system/etc. Any help will be hi-5-tastic! I want that my script remotely download a file on the server from another server and save it remotly on the server.
For example my script is located on http://mydomain.com/...load_script.php
The file I want to download is on http://otherdomain.com/file.zip
Then I want to save it to http://mydomain.com/file.zip ----------- to the local server folder
I found a way how to parse HTML code remotly, but haven't found how to download files, please help me to find the right function.
|