PHP - Word Tally
Hi: I can't seem to figure out how I would display the words the user enters in an ordered list on the bottom of the page in the <div id="guesses"> area. A hidden form variable is used to store all the previous guesses. (no cookies, no session variables).
Also, how do I get the guesses to appear in the top of the page so that it looks like this: Array ( [myguess] => eee [alltheguesses] => aaa|ccc|ddd|ggg ) This is what I seem to be getting: Array ( [myguess] => yy [allTheGuesses] => ) Code: [Select] <?= '<pre>' . print_r($_POST,true) . '</pre>'; ?> <? $WORDS = array("grape","apple","orange","banana","plum","grapefruit"); define ("GUESSINDEX",3); define("THEWORD",$WORDS[GUESSINDEX]); foreach ($WORDS as $val){ if ('banana' == $val) echo 'found it.'; else echo 'not found.'; } if (in_array('plum',$WORDS == true)){ } foreach ($guessesarr as $val) echo "<li> $val</li>"; foreach ($WORDS as $val) echo "$val | "; echo "<br>"; echo implode(' | ',$WORDS); ?> <html> <style type="text/css"> body {background-color:orange} div {margin:10px} div#container {background-color: white; border: 3px solid black;width: 400px;margin-right: auto;margin-left: auto; text-align:center;} div#error {color:red} div#guesses,div#header p span {color:green; } h1,h2,h3 {color:#633} </style> <body> <div id="container"> <div id="header"> <p>grape | apple | orange | <span>banana</span> | plum | grapefruit</p> <h1>Word Guess</h1> <a href="<?$_SERVER['PHP_SELF']?>">refresh this page</a> </div> <div id="form"> <h3>Guess the word I'm thinking</h3> <form name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>" > <input name="myguess" type="text" value="<? echo $_POST['myguess']; ?>"> <input type="hidden" name="allTheGuesses" value = "<? echo $_POST['allTheGuesses']; ?>"> <input type="submit" value="GUESS"> </form> </div> <div id="error"> <? if ($_SERVER['REQUEST_METHOD'] == 'GET') echo "It's time to play the guessing game! (1)"; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $MYGUESS = trim($_POST['myguess']); if ($MYGUESS == "") echo "C'mon, guess something (2)"; elseif (in_array($MYGUESS,$WORDS) == false) echo "Hey, thats not even a valid guess. Try again (5)"; elseif ($MYGUESS == THEWORD) echo "You guessed " . THEWORD . " and that's CORRECT!!! (3)"; elseif ($MYGUESS <> THEWORD) echo "Sorry $MYGUESS is wrong. Try again (4)"; } ?> </div> <div id="guesses"> <center> <? echo "<ol>"; $allguesses = trim($_POST['allTheGuesses'],", "); $guessarr = explode(", ", $allguesses); foreach( $guessarr as $guess ){ echo "<li>$guess</li>"; } echo "</ol>"; ?> </center> </div> </div> </body> </html> Similar TutorialsHi guys, I'm trying to export records from php to ms word which appends text + image. i have got this code from http://www.thaicreate.com/php/php-word.application-addpicture.html Code: [Select] <html> <head> <title>ThaiCreate.Com PHP Word.Application Tutorial</title> </head> <body> <? $wdColorDarkRed = "&H80"; $wdAlignParagraphCenter = "1"; $wdAlignParagraphLeft = "0"; $wdParagraph = "4"; $wdHorizontalPositionMargin = "0"; $wdTableLeft = "-999998"; $wdCollapseEnd = "0"; $Wrd = new COM("Word.Application"); $DocName = "MyDoc/MyWord.doc"; //$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp $Wrd->Application->Visible = False; $WrdDoc = $Wrd->Documents->Add(); $MyRange1 = $WrdDoc->Paragraphs->Add->Range; $MyRange1->ParagraphFormat->Alignment = $wdAlignParagraphCenter; $MyRange1->Font->Name = "Verdana"; $MyRange1->Font->Size = "30"; $MyRange1->Font->Bold = True; $MyRange1->InsertBefore(chr(13).chr(13)."www.ThaiCreate.Com".chr(13)."Version 2009"); $MyRange1->InlineShapes->AddPicture(realpath("thaicreate-2009.gif")); //$WrdDoc->InlineShapes->AddPicture(realpath("thaicreate-2009.gif")); //$WrdDoc->Shapes->AddPicture(realpath("thaicreate-2009.gif"),0,0,MyRange1); //$WrdDoc->Shapes->AddPicture(realpath("thaicreate-2009.gif"),0,0,Wrd->Selection->Range); $MyRange2 = $WrdDoc->Paragraphs->Add->Range; $MyRange2->ParagraphFormat->Alignment = $wdAlignParagraphCenter; $MyRange2->Font->Name = "Verdana"; $MyRange2->Font->Size = "15"; $MyRange2->Font->Bold = True; $MyRange2->InsertBefore(chr(13).chr(13)."PHP,ASP and ASP.NET Tutorial"); $MyRange2->InlineShapes->AddPicture(realpath("doc.gif")); $MyRange3 = $WrdDoc->Paragraphs->Add->Range; $MyRange3->ParagraphFormat->Alignment = $wdAlignParagraphCenter; $MyRange3->Font->Name = "Verdana"; $MyRange3->Font->Size = "10"; $MyRange3->Font->Bold = True; $MyRange3->Font->Color = $wdColorDarkRed; $MyRange3->Underline = True; $MyRange3->InsertBefore(chr(13).chr(13).chr(13).chr(13)."All Rights Reserved"); //$WrdDoc->SaveAs($strPath."/".$DocName); $WrdDoc->SaveAs(realpath($DocName)); $Wrd->Application->Quit; $Wrd = null; ?> Word Created <a href="<?=$DocName?>">Click here</a> to Download. </body> </html> This is the best code i've found so far that guides on how to format the text in ms word via PHP. All set to go but one thing that I am trying to accomplish : to have a clickable email address (hyperlink) in the same ms word file. i have got this code somewhere from the net: Code: [Select] $MyRange3->Hyperlinks->Add({range}, 'http://www.google.com', '','',' hyperlink text to display'); // where {range} refers to as anchor according to that website this methods could be found in ms word visual basic editor (Alt+F11) then object browser (F2) when i replace the {range} above with let say variable $MyRange3. Code: [Select] $MyRange3->Hyperlinks->Add($MyRange3, 'http://www.google.com', '','',' hyperlink text to display'); The output will be produced but overwriting everything in $MyRange3 and displays only the hyperlink. I would like the email address (hyperlink) to appear at the end of $MyRange3 text. example output Code: [Select] All right reserved [u]hyperlink text to display[/u] anyone can shed some light on this. Hey guys i found this script that works great for what i need .. se i have this script that i did for my body (loan application) now i would like to export the info in a word doc <?php $ExcelFileName="test.doc"; header("Content-type: application/x-ms-download"); header("Content-Disposition: attachment; filename=$ExcelFileName"); header('Cache-Control: public'); $content=<<<EOD echo 'php'; whatever you want to write here including a php script it will be included in a string and then go in the output for a doc file EOD; echo $content; ?> so im trying to eco all the content in the database.. i tryed all the DB connection is there.. ao i place this after the (echo 'php' while($info = mysql_fetch_array($fileLIST)){; echo $info['PERS_F_NAME']; }; i get this? Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/autosspe/public_html/admin/loan/word.php on line 21 I have this code below the browser shows correct data but when i export to word I see $proc output not the switch data like on the the browser page
How should code be written to show the same on word doc .
I'm new to this learning by trial and error Please go easy on me .
Thanks
<td> <? I'm going to post the code that I am currently using and then explain what I'm trying to do. I hope I can explain it well enough. <?php if (!isset($_POST['submit'])) { echo'<leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"> <center><form name="fairlistlist" method="POST" action="'.$_SERVER['PHP_SELF'].'"> <TABLE width="450" height="119" border=0 cellPadding=3 cellSpacing=2 bgcolor="#fff568"> <TBODY> <TR> <TD class=mainText width="100"><b>Event Name</b></TD> <TD width="305" class=frmInput> <INPUT class=mainFormBox style="WIDTH: 320px" type="text" name=" fairname"></TD> </TR> <TR> <TD class=mainText width="100"><B>Event Address</B></TD> <TD class=frmInput> <INPUT name="fairadd" type="text" class=mainFormBox id="fairadd" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event City</b></TD> <TD class=frmInput> <INPUT name="faircity" type="text" class=mainFormBox id="faircity" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event County</b></TD> <TD class=frmInput> <INPUT name="faircty" type="text" class=mainFormBox id="faircty" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event State</b></TD> <TD class=frmInput> <INPUT name="fairstate" type="text" class=mainFormBox id="fairstate" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Country</b></TD> <TD class=frmInput> <INPUT name="fairctry" type="text" class=mainFormBox id="fairctry" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Opening Date</b></TD> <TD class=frmInput> <INPUT name="fairopen" type="text" class=mainFormBox id="fairopen" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Closing Date</b></TD> <TD class=frmInput> <INPUT name="fairclose" type="text" class=mainFormBox id="fairlose" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Contact Email</b></TD> <TD class=frmInput> <INPUT name="fairmail" type="text" class=mainFormBox id="fairmail" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=mainText width="100"><b>Event Website</b></TD> <TD class=frmInput> <INPUT name="fairweb" type="text" class=mainFormBox id="fairweb" style="WIDTH: 320px"></TD> </TR> <TR> <TD class=frmDescription width="56"> </TD> <TD class=frmInput> <div align="right"> <input type="submit" name="submit" value="Add my Event" /> </div></TD> </TR> </TBODY> </TABLE> </form></center> </body>'; //note that I added a new field called submit and it's hidden .. } else { /*I added addslashes() so it escape any special char in the form .. if you want to show your inserted record , you need to use stripslashes() to remove any slashes from the record .. this is only to avoid some security problems in the query ..*/ $fairname=trim(addslashes($_POST['fairname'])); $fairadd=trim(addslashes($_POST['fairadd'])); $faircity=trim(addslashes($_POST['faircity'])); $faircty=trim(addslashes($_POST['faircty'])); $fairstate=trim(addslashes($_POST['fairstate'])); $fairctry=trim(addslashes($_POST['fairctry'])); $fairopen=trim(addslashes($_POST['fairopen'])); $fairclose=trim(addslashes($_POST['fairclose'])); $fairmail=trim(addslashes($_POST['fairmail'])); $fairweb=trim(addslashes($_POST['fairweb'])); include("Connections/local.php"); $link = mysql_connect($hostname_local,$username_local, $password_local) or die("Could not connect"); mysql_select_db('fair123') or die("Could not select database"); $insert=mysql_query("INSERT INTO events (fairidnum, fairname, fairadd, faircity, faircty, fairstate, fairctry, fairopen, fairclose, fairmail, fairweb) VALUES('NULL', '$fairname', '$fairadd', '$faircity', '$faircty','$fairstate', '$fairctry','$fairopen', '$fairclose', '$fairmail', '$fairweb')")or die('couldn\'t Insert record into database :'.mysql_error()); header( 'Location: event_added.php' ) ; } ?> Especially look at the code part here $insert=mysql_query("INSERT INTO events (fairidnum, fairname, fairadd, faircity, faircty, fairstate, fairctry, fairopen, fairclose, fairmail, fairweb) VALUES('NULL', '$fairname', '$fairadd', '$faircity', '$faircty','$fairstate', '$fairctry','$fairopen', '$fairclose', '$fairmail', '$fairweb')")or die('couldn\'t Insert record into database :'.mysql_error()); header( 'Location: event_added.php' ) ; } ?> this is where I am having problems it was reading echo your record has been successfully added to the database What I want is for it to open up a new page with my menu and my css and all that good crap to a page where it will read the following Your information has been added to our database We have added Event name = "whatever the event's name was" Event address = "address:" so on and so on for all the fields in my form that was submitted to the database. with just using the echo command it always opened to just a blank page no formatting and no css as well as no all important links Can you please tell me what I'm doing wrong or where I can find a good guideline that Is easy to understand on how to do this? Thanks in advance Oh also I don't care if that page get's indexed by google or yahoo or not actually prefer it don't get indexed to be honest Hi all, I don't know if it is possible but i need to edit one word document, write the name of the customer in it, but at the right place and print it from a php form. The user write in that php form the customer id and if he exists, the system should modify the word template and print it. Do you think this is possible and if so how can i do that? Thanks in advance. Hugo How can I sort a string alphabetically? I thought about creating an array ('a'=>0, 'b'=>1) etc, but didn't manage to work. So how can I do this? is there a predefined function for this? or I should create the algorithm? Thanks, Example: $word = 'cbad432'; // should become: '234abcd' I have a CMS with basic toolbar and have major issues with copying and pasting from MS Word. I have a code below that I would like to test cleaning up MS Word.... Code: [Select] <?php function word_cleanup ($str) { $pattern = "/<(\w+)>(\s| )*<\/\1>/"; $str = preg_replace($pattern, '', $str); return mb_convert_encoding($str, 'HTML-ENTITIES', 'UTF-8'); } ?>And would like to add it onClick within code below, but it doesn't seem to do anything...... Code: [Select] <?php //we will have to dynamically generate either the edit and delete buttons or //the save button here depending on numevent. if($numMain!=-1) { echo("<tr><td colspan='2' align='center'><input type='submit' id='button' name='edit' value='Save Changes' onClick=\"saveChanges('edit'); onClick=\"function('word_cleanup');\"><input type='submit' id='button' name='delete' value='Delete' onClick=\"saveChanges('delete');\"></td></tr></table></form>"); } else { echo("<tr><td colspan='2' align='center'><input type='submit' id='button' name='save' value=' Save ' onClick=\"saveChanges('save'); onClick=\"function('word_cleanup');\"></td></tr></table></form>"); } ?> Any help, tips, suggestions would be so greatly appreciated. Hey, I have a word filter which is dectecting strings that are only embedded in words. Which i don't want it to do. For example: If i want to filter "FR" and some one puts france - it flags it because france contains FR. How do i make it only look for "FR" on its own seperated from a word instead of it flagging nearly all words with the two letters together? Heres my filter: $text = 'testing'; //this should not return 1 // fill this array with the bad words you want to filter and their replacements $bads = array ("test"); foreach($bads as $key => $search_needle) { if(stristr($text, $search_needle) == TRUE) { return(1); break; } } I want to catch the first word of a string in which the words are separated by "-" (e.g. "first-word-second-one-more"). I used this code: $string = explode('-', $string); echo $string[0]; The problem is that when the string contains only one word, it returns null I have a table in my php Mysql which contains some values.. Is it possible to get those values then export them to MS word with formatting? and make it like a table? Help pls. how to take a word in php or explode based on luas Bangunan :xxx For example I have string $string =" Kondisi Properti : Bagus Dilengkapi Perabotan : Unfurnished Sertifikat : Lainnya Daya Listrik : 2200 Watt Kamar Tidur : 3/1 Kamar Mandi : 2/1 Luas Bangunan : 92 m² Luas Tanah : 126 m² Jumlah Lantai : - Kondisi Properti : Bagus Sekali Dilengkapi Perabotan : Unfurnished Sertifikat : SHM - Sertifikat Hak Milik Daya Listrik : 6600 Watt Saluran Telepon : 1 Garasi : 3 Kamar Tidur : 4/1 Kamar Mandi : 3/1 Luas Bangunan : 300 m² Luas Tanah : 228 m² Jumlah Lantai : 2.5 "; eg I want to take every "Luas bangunan: xxx" Thanks Good evening, I hope some of you can bring me some hope to solve this problem. My client wants to create pdf files and let the user download it. He want's to design one word file and then import it to the application. After that the portal users can request it, which means that the application should take the word file, search and replace some keywords and then create the pdf file for download purposes. I see fpdf but this class only create pdf's. We can not convert from word or even search and replace in one pdf file. There is any solution that i can use bear in mind that our application is located in external servers? Looking forward for your help. Regards, HS hey im tring to match words which contain double s at the end...ie. address, business, class etc...so that is so i can put a ' at the end...
class'
if (preg_match("/ss$/", $name)) { $name = $name . "'"; }any help with the regular expression would be great thank you Hi there, Can someone tell me an easy way to highlight a word in a page using PHP? I only need to highlight 1 word, for example "hello". Thanks Hello Guys, I need some help here.. I want to implement a Bad word filter and not quite sure how to do it.. I am grabbing the following vars from the text fields $ad_title = filter_var($_POST['ad_title'], FILTER_SANITIZE_STRING,FILTER_FLAG_NO_ENCODE_QUOTES); $ad_body = filter_var($_POST['description'], FILTER_SANITIZE_STRING,FILTER_FLAG_NO_ENCODE_QUOTES); Then its inserted into the db. I would like to run it through this function first.. Code: [Select] FUNCTION BadWordFilter(&$text, $replace){ // fill this array with the bad words you want to filter and their replacements $bads = ARRAY ( ARRAY("butt","b***"), ARRAY("poop","p***"), ARRAY("crap","c***") ); IF($replace==1) { //we are replacing $remember = $text; FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word $text = EREGI_REPLACE($bads[$i][0],$bads[$i][1],$text); //replace it } IF($remember!=$text) RETURN 1; //if there are any changes, return 1 } ELSE { //we are just checking FOR($i=0;$i<sizeof($bads);$i++) { //go through each bad word IF(EREGI($bads[$i][0],$text)) RETURN 1; //if we find any, return 1 } } } // this will replace all bad words with their replacements. $any is 1 if it found any $any = BadWordFilter($wordsToFilter,1); I really would also like to query a table for any words that match and then use a replacement like [censored] Any help would be greatly appreciated! Hello, I had created a form for users to upload their resumes (only word documents & 1 MB allowed as size), then email it after its been successfully uploaded. Any help? Thanks in advance Hi there, I'm learning PHP and decided that I'll try to create a word search generator for my own use. I know there are hundreds of them out there but it's just for learning purposes. I'd like to enter a number of words and then the script should generate a pdf containing a box filled with random letters (among which there will be my words). My question is what keywords/functions should I look at to get started? I'm a php beginner but would like to make my learning more interesting by doing this project. The form with words should be easy, it's the next bit where it's supposed to generate a pdf containing words that I have no idea about. thank you Hey guys, any suggestions how i could read and write msWord files without using the COM interface. I need to keep all the formatting intact though... any ideas? many thanks For some reason, this doesn't work:
<?php $string = 'You have a code CODE code of ethics'; while (preg_match("/code\s+code/",$string)) { $string = preg_replace("/code\s+code/","code",$string); } print $string; ?> I don't want to replace all instances of duplicated words, rather, only when the word "code" is duplicated. Throughout my 100mb text file, the word "code" appears duplicated (with varying whitespace between). For example: From this: You have a code CODE code code of ethics. Code code Code green means everything is okay. What is the CODE code code code for the lock. To this: You have a code of ethics. Code green means everything is okay. What is the code for the lock. But for some reason, I cannot get my preg_replace to work? Hello I was wondering if anyone could help me. I have bought a script that are encoded is something that i cant change or read, and i have ask the owner how to put a {user} at the end of every hyperlink so are going to a other site, but he said you need a external script to do that. So was wondering if anyone could help me. Im using a database where all the user are etc But If i go to google.com and login as Bobmartin I will be at google.com/home Then i click on a hyperlink inside google.com/home that will bring me to a other side Lets say the hyperlink (other site) is www.phpfreaks.com/profile/ So when i begining to redirect to www.phpfreaks.com/profile/ the script will add {user} from the database So at the end i will be redirect to www.phpfreaks.com/profile/Bobmartin The hyperlink is generated in a unique code so i cant just add {user} it must be a external script i need to use. So to say it fast I want to add /{user} for every hyperlink that is redirect to another site without add {user} direct to the hyperlink for example www.google.com/{user}, the hyperlink must me www.google.com Well i hope you guys understand this, im not the best person to explain things so Also my english suck so dont judge me |