PHP - How To Go About Creating An Anagram Solver?
Hey guys!
I have a word list but I'm not really sure where to start to create an anagram solver. A push in the right direction would be great! Thanks Similar Tutorialshey guys i wrote an quick and dirty anagram solver for a challenge on hts which works great but i am more interested on feedback of how I could have written it better / more efficiently. anyone have there own version of writing this? thanks Code: [Select] $scramwords = array("htssboe","rtefcelh","vteevl","edsiyn","awloddno","dtey1d","kuedci","seellhy","sernin","acianro"); $unscramwords = array(); $filename = '../wordlist.txt'; // loop through scrambled words foreach($scramwords as $scramword) { // open the file if($fh = fopen($filename,'r')) do { // read line $line = fgets($fh); // see if line and scrambled word are same length if((strlen(trim($line))) == (strlen(trim($scramword)))) { //if they are the same length split the line into and array and the scrambled word into an array $l = array(); for($i=0;$i<strlen(trim($line));$i++){ $l[$i] = substr(trim($line),$i,1); } $s = array(); for($i=0;$i<strlen(trim($scramword));$i++){ $s[$i] = substr(trim($scramword),$i,1); } $errors = 0; // see if the arrays are different $chk = array_diff($l,$s); if(!empty($chk)){ $errors = 1; } // see if arrays are different in reverse order $chk2 = array_diff($s,$l); if(!empty($chk2)){ $errors = 1; } // found scrambled word if(!$errors) { array_push($unscramwords,$line); } } }while(!feof($fh)); fclose($fh); } // print out comma seperated un scrambled words echo implode(",",$unscramwords); I need to write a function which comes two strings to find out if string 1 is an anagram or a palindrome For example the function should return 1 for the argument "dooernedeevrvn", because it is an anagram of a palindrome "neveroddoreven". For argument "aabcba", your function should return 0. I'm not really sure where to start so if anyone has done anything similar then any help would be great. Thanks for any help. Does anyone know how to make an excel solver function in php? How can you say... maximize this variable by adjusting these other variables? Hello everyone, I found a tutorial on creating a pdf with php and I just tried to create a basic pdf to see if it worked and modify it from there. Here is the link to the tutorial: http://www.astahost.com/info/tfclt-create-pdf-php-create-fly-pdf-web-server.html Well, after uploading the following php file to the server and testing it, I got this error: Fatal error: Call to undefined function pdf_new() in /home/caresa6/public_html/BubblyBounce.com/admin/pdftest.php on line 2 Here's the code that produced the error: Code: [Select] <?php $mypdf = PDF_new(); PDF_open_file($mypdf, ""); PDF_begin_page($mypdf, 595, 842); $myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0); PDF_setfont($mypdf, $myfont, 10); PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750); PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730); PDF_end_page($mypdf); PDF_close($mypdf); $mybuf = PDF_get_buffer($mypdf); $mylen = strlen($mybuf); header("Content-type: application/pdf"); header("Content-Length: $mylen"); header("Content-Disposition: inline; filename=gen01.pdf"); print $mybuf; PDF_delete($mypdf); ?> Can anyone help me figure out what to do from here? I have some PHP knowledge, but I'm treading in uncharted waters with this, so I am totally lost. Thanks in advance. Code: [Select] SELECT * FROM table1,table2,table3,table4,table5 WHERE table1_f = table2_id AND table1_g = table3_id AND table4_p = table1_id AND table5 _m = table4_id ORDER BY RAND() LIMIT 1 Right, Now What I want to do, is have a filter form, which posts to the above, and if: $filter1 = ""; it wont be include in the above code $filter1 = "word"; then i want to include AND table3_n = '$filter1'; in the above code thanks in advance. Hello all I have a requirement to create images mostly made up of rectangles circles and squares etc I have discovered imageline but is there anything a bit more exspansive? I have set up a database using myPHPadmin, I have created the following code: Code: [Select] <?php session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("127.0.0.1","root","password") or die("Couldnt connect to database"); mysql_select_db("login") or die ("Couldnt find database"); $query = mysql_query("SELECT * FROM users WHERE username ='$username'"); $numrows = mysql_num_rows ($query); if($rumrows != 0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&$password==$dbpassword) { echo "Login successful. <a href='members.php'> Click here to enter memebers area </a>"; $_SESSION['username']=$dbusername; } else echo "Incorrect password"; } else die ("Username does not exist"); } else die ("Please enter a username and password"); ?> Even though the database is set up when i try and enter the username for the log in page and password, it says the username does not exist? I dont understand why when it is in the database? Please help! MOD EDIT: [code] . . . [/code] BBCode tags added. i need to create a to do list with php. but i dont want to use database .is there anything else i can use instead of using a database? i need to delete ,add functions .how may i do this? basicly it will have process.php,index.php and delete.php it may need more pages though. im a beginner so , code shouldnt be complicated and should be with explanation please . thanks. I am trying to create a madlibs game .. I have a txt file with paragraphs in it .. Some of the sentences have the following tags in it <#noun>, or <#verb>, etc ... I need to parse the file in php and display the content in between the tags to the user. The user can fill the the words in text box, and the story will be displayed with the new words instead of the tags. I am new to php. Any help greatly appreciated. Thanks in Advance, Vladimir Hi, I need help please with creating a cron job. I have the following sql commands that need to take place within the cron job. This is all i need to do every couple of hours, thus the reason for a cron job. Code below: DELETE FROM tmpsessionmodule; INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module1 FROM session WHERE ((Module1) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module2 FROM session WHERE ((Module2) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module3 FROM session WHERE ((Module3) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module4 FROM session WHERE ((Module4) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module5 FROM session WHERE ((Module5) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module6 FROM session WHERE ((Module6) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module7 FROM session WHERE ((Module7) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module8 FROM session WHERE ((Module8) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module9 FROM session WHERE ((Module9) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module10 FROM session WHERE ((Module10) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module11 FROM session WHERE ((Module11) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module12 FROM session WHERE ((Module12) <>"" ) Can someone please help me!! Any assistance will be greatly appreciated. Thanks! hi i open this post so i dont open 5 new ones ok i have a task to do an event calendar now i found some tutorial for creating simple calendar BUT all of them are on english what i need is change it to croatian - that means i have custom names for days, custom names for months, and what i also need is put sunday where it belongs... at the end because we are calculating week starts by monday... so any tips? if you know some tutorial that works for these spec things i googled it but i only found like 2 calendars that actualy works other have some bugs in scripts and wont do thing or just write me tips and ill try to create it hey guys, im new to all this php stuff. I have a project in this semester to create an HR contract system for the university, here are my requirements: 1. Add Contracts 2. Delete Contracts 3. Edit Contracts 4. View Contracts 5. Search Contracts i have done all the 4 options but now im stuck in the 5th option. i have to use checkboxes filters for search and first and the last name fields. here is my form code <form method="post" action="searchCode.php"> First Name: <input name="name" type="text" id="name" /> Middle Name: <input name="mname" id="mname" type="text" /> Last Name: <input name="lname" id="lname" type="text" /> Date: <input type="text" name="date" id="currentdate" /> <input type="checkbox" name="gender[]" value="male" />Male<br /> <input type="checkbox" name="gender[]" value="female" />Female <input name="desig[]" type="checkbox" value="lecturar"/>Lecturar <input type="checkbox" name="desig[]" value="professor" />Professor <input type="checkbox" name="desig[]" value="assistantProfessor" />Assistant Professor <input type="checkbox" name="desig[]" value="associateProfessor" />Associate Professor <input type="checkbox" name="desig[]" value="researchAssociate" />Research Associate<br /> <input type="checkbox" name="desig[]" value="advisor" />Advisor <input type="checkbox" name="desig[]" value="HOD" </span> <input name="dept[]" type="checkbox" value="Comuter Science" />Computer Science <input type="checkbox" name="dept[]" value="Health Informatics Unit" />Health Informatics Unit <input name="dept[]" type="checkbox" value="Electrical Engineering" />Electrical Engineering <input type="checkbox" name="dept[]" value="Management Sciences" />Management Sciences<br /> <input type="checkbox" name="dept[]" value="Mathamatics" />Mathamatics <input type="checkbox" name="dept[]" value="Physics" />Physics <input type="checkbox" name="dept[]" value="Bio Sciences" />Bio Sciences <input type="checkbox" name="dept[]" value="Meteorology" />Meteorology <input type="checkbox" name="dept[]" value="Architecture" />Architecture <input name="scales[]" type="checkbox" value="sg1" />SG-I <input name="scales[]" type="checkbox" value="sg2" />SG-II <input name="scales[]" type="checkbox" value="sg3" />SG-III <input name="scales[]" type="checkbox" value="sg4" />SG-IV <input name="scales[]" type="checkbox" value="ras" />RA <input name="scales[]" type="checkbox" value="og1nphd" />OG-I- <input name="scales[]" type="checkbox" value="og2nphd" />OG-II-NonPhd <input name="scales[]" type="checkbox" value="og3nphd" />OG-III-NonPhd <input name="scales[]" type="checkbox" value="og4nphd" />OG-IV-NonPhd <input name="scales[]" type="checkbox" value="og2phd" />OG-II-Phd <input name="scales[]" type="checkbox" value="og3phd" />OG-III-Phd <input name="scales[]" type="checkbox" value="og4phd" />OG-IV-Phd</p> now i cant seem to get it in my mind tht how the hell im going to do tht...shud i use ifs and elses, in tht case it can get upto 256 combinations. and 1 more thing all these things are in one table....please gyus help me Hi, I am trying to create a cron job that truncates a database table, then inserts data back into the table, The cron jobs works fine, if i just truncate the table, but does not seem to work if i want to re-insert data back in the table. truncate.php looks as follows: <?php require_once('/usr/www/users/amisea/sosams/db-connecter.php'); $query = "TRUNCATE TABLE tmpsessionmodule; INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module1 FROM session WHERE ((Module1) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module2 FROM session WHERE ((Module2) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module3 FROM session WHERE ((Module3) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module4 FROM session WHERE ((Module4) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module5 FROM session WHERE ((Module5) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module6 FROM session WHERE ((Module6) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module7 FROM session WHERE ((Module7) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module8 FROM session WHERE ((Module8) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module9 FROM session WHERE ((Module9) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module10 FROM session WHERE ((Module10) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module11 FROM session WHERE ((Module11) <>"" ); INSERT INTO tmpsessionmodule (SessionNo, Module) SELECT SessionNo, Module12 FROM session WHERE ((Module12) <>"" );" $result = @mysql_query($query); ?> Is there a way to use PHP to edit html without having to store it in my DB? For example I would like someone to be able to edit a paragraph on the page, its wrapped in a <div class="editable"> now is there a way to have PHP detect that div and have an textarea to edit it directly without having to store anything in a DB? I hope that makes sense if it doesn't let me know! Thanks I am trying to create random no. of directories but its always giving this error Warning: mkdir() [function.mkdir]: Invalid argument in C:\xampp\htdocs\gl\movie_process.php on line 173 the code is for(i=0; i<5; i++) { mkdir("".$base."uploads/movies/$year/$month/$title/".$hosting[$i].""); } i am able to create csv's and can do so with no trouble .. but what i am having difficulty with is being able to auto save the csv and then email it all in one script. anybody every dealt with something like this? I am in the process of creating a like system for a personal website that I am working on. I am trying to pull information from one database and use that to place info into another database. When I do I get resource error #15. This is my code that I have so far Code: [Select] function like_add() { $last = $_GET['l']; $first = $_GET['f']; $ip = $_SERVER['REMOTE_ADDR']; $like_sql = "Select * from `counter` where first = ' $first ' and last = '$last '"; $like_result = mysql_query($like_sql); $likes = '<p class="like_button"> Likes '; while ($like_row = mysql_fetch_assoc($like_result)) { $like = $like_row['likes']; $likes .= " $like"; } $likes .= '</p>'; echo "$likes"; echo '<form name="like_add_form" action="" method="POST" class="like_add"> <input type="submit" name="like_add" class="like_add_button" value="Like Me" /> </form>'; if (isset($_POST['like_add'])) { $page_id = "SELECT `page_id` FROM `counter` WHERE first = '$first' AND last = '$last'"; $page_id_result = mysql_query($page_id); echo $page_id_result; <----- Here I am trying to pull information from a field in my database to use as a variable and to place in the second database $voted = mysql_query("Select * FROM `liked_ip` where ip ='$ip' AND page_id='$page_id_result'"); <----- Here I want to use the information from the first table to place in the second one if (mysql_num_rows($voted) != 0) { echo "You have all ready liked this post"; } else { mysql_query("INSERT into `liked_ip`(id,page_id,ip) VALUES ('$page_id_result','$ip')"); } if (mysql_num_rows($voted) == 0) { mysql_query("UPDATE counter SET `likes` = `likes` + 1 where first = '$first' AND last = '$last'"); } } } I know that I have to be doing something so simple that I am just not seeing it this late at night. I may even be completely wrong in all of this. If someone could please help me out I would appreciate it very much. I want to create an image using pre-existing image files. I want to use more than one file, otherwise I would use the imagecreatefromjpg function. What function should I use to create an image using a for statement to determine how many of each image is being displayed in the new image? Hello, On my website I wish to have a simple graphic and allow users to write their own text onto the graphic then they can save out the graphic. I'm new to PHP so I'm not that good at it. I've done some research and I think I need to use the GD library. Is this correct? What would be the easiest way to do what I want? Thanks |