PHP - Need To Echo All Word Combinations From The Input
need to echo all word combinations from the input
also lets say that someone types "this is my query" into an input fiend and this will be the input. i need the php script to echo all the possible combinations of this string. but there can be 4 words like in the example or 3 or more or less. also it should then echo something like this: this this is this is my this is my query is is my is my query is my query this my my query my query this my query this is query query this query this is query this is my + query is my this this my query is also all combinations possible, for 1 word, 2 words, ... max. words inputed. Similar TutorialsHello phpfreaks I'm a bit new to PHP, as well as this forum. I'm learning in a fast way, but there's something I can't seem to figure out, nor find it on google. I'm sure it's a simple and basic trick, but like I said, I'm just a beginner So the question is: How can I store multiple words to an array, using only 1 input form field? I guess it's with a for-loop..? So everytime you hit the 'submit' button, a new word should be added to the array. My problem is that I'm always overwriting ONE word.. This is what I've got so far.. : Code: [Select] <?php if (isset($_POST['word'])){ $word = $_POST['word']; $word = strip_tags($word); $word = trim($word); $word = htmlentities($word); } else { $word = ""; } ?> <div id="arrays"> <p>Add a word to the array below:<br /><br /></p> <form action="index.php" method="post"> <input id="word" name="word" type="text" value="<?php echo $word; ?>" /> <br /><input class="btn" type="submit" value="Submit" /> </form> <br /> <p> <?php $array = array("apple", "banana", "lemon", $word); for ($i = 0; $i < count($array); $i++){ echo $array[$i] . " "; } ?> </p> </div> Also: I'm using PHP 5, in combination with xHTML strict 1.0. Hi guys I have created a profile page where users can update their profile. what I need to do is to echo back the users details in the inout text I have name and telephone number any ideas how to do it? here is my code <?php session_start(); include ("global.php"); //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; //welcome messaage echo "Welcome, " .$_SESSION['username']."!<p>"; if ($_POST['register']) { //get form data $name = addslashes(strip_tags($_POST['name'])); $telephonenumber = addslashes(strip_tags($_POST['telephonenumber'])); $query = "UPDATE users SET name = ' $name' WHERE username='$username'"; $result = mysql_query($query); $query = "UPDATE users SET telephonenumber = ' $telephonenumber' WHERE username='$username'"; $result = mysql_query($query); } ?> <form action='updateprofile.php' method='POST'> Company Name:<br /> <input type='text' name='name'><p /> <input type='text' name='telephonenumber'><p /> <input type='submit' name='register' value='Register'> </form> _______ the reason i want to do this is because when user is updating the name field the empty input text for telephone number ovverides the telephone number field in the database. I would aprreciate your help guys, How can i simply put the input box at the end of echo $page_pagination; instead of dropping down to a new line. Code: [Select] echo $page_pagination; echo '<FORM NAME="Library Search" ACTION="z3950get.php" METHOD="POST">'; echo '     Or go to page number '; echo '<input type="text"SIZE="5" name="pageinput2" value="'. $page_num.'">'; echo '<input type="hidden" name="recordcount" value="'.$recordcount.'"/>'; echo '<button type="submit" name="pageinput1" value="search">Search</button>'; echo '</FORM>'; echo '<BR><BR>'; echo 'Showing Page Number -> '.$page_num. ' | Total number of results -> '.$numrows . ' | Total number of pages -> '.$numofpages.'<BR><BR>'; Hello, Am looking for a function that generates all possible combinations of strings in an array. For example if: $arr[1] = "Hello"; $arr[1] = "how"; $arr[2] = "are"; $arr[3] = "you"; When the array is passed through the function you would come up with a list of string combinations line by line like below: Hello Hello how are you how Hello are you how are Hello you how are you Hello how ........and so on The list goes on and on. Ok, So what I need is a way for arrays to combine. My basic structure is going to look like this for the form that needs submission: Code: [Select] <form> <input name="name[]" /> <input name="name1[]" /> <input name="name[]" /> <input name="name1[]" /> <input name="name[]" /> <input name="name1[]" /> </form>then on the page it submits to, I need an array to form that will combine all the inputs to looks something like this: "name" "name1"; "name" "name1"; "name" "name1";.......... where the first set is the first name and name1, second is second, third is third, etc. The string of arrays will only end when there are no more left, so if there were 6, it would combine 6. how do I do something like this? Hi. I need some help working something out. I have an array that has all the numbers from, 0 to 9. What I want to do is loop through the array to make all the combinations possible up to a string thats 255 chars long. $array = array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ); Should be looped through to create strings like this: Code: [Select] 0 1 2 3 4 5 6 7 8 9 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 etc.. Just as if it's counting. I searched online and seen some complex c and c# code which I didn't understand much of. But how do I generate an array with all string combinations based on length and from a charset? E.g. charset = {'a', 'b', 'c'} Length = 2. Then it should generate first all 1-char strings: a b c Then all 2-char strings: aa ab ac ba bb bc ca cb cc And then all added to the same array. I think there's some way of doing it with recursion but to me it's like thinking with a 4th dimension my mind can't grasp this logic! Hi PHPfreaks, I've got a problem Ive been faced with a few days now, and for the life of me Im unable to solve it. What I have is a multidimensional array, that I need to parse and retreive every possible outcome possible Below is a basic example of how the array would look Code: [Select] Colour Black White Blue Finish Matt Gloss What I need to be able to do is, as I said, Show all the possible combinations there is. below is what i'd have achieved after one of you helpful souls points me in the right direction. Code: [Select] --> Color: Black --> Color: White --> Color: Blue --> Finish: Matt --> Finish: Matt --> Color: Black, Finish: Matt --> Color: White, Finish: Matt --> Color: Blue, Finish: Matt --> Color: Black, Finish: Gloss --> Color: White, Finish: Gloss --> Color: Blue, Finish: Gloss As you can see, Only ONE (or no) value is picked from each section. Just to confirm: the number of option groups WILL change...... So I could have colour, finish, size, weight and many more. the number of values in the groups WILL change....... so under colour, I could also have pink, green, indigo, gray. Below is how this array is structured Code: [Select] Array ( [0] => Array ( [parent] => Colour [values] => Array ( [0] => Array ( [name] => Black ) [1] => Array ( [name] => White ) ) ) [1] => Array ( [parent] => Finish [values] => Array ( [0] => Array ( [name] => Matt ) [1] => Array ( [name] => Gloss ) ) ) ) Would anyone have any suggestion on how this can be done? I've pulled out every single strand of hair I've got now, so thought i'd admit defeat and let someone else have a go Many thanks inadvance. I'm trying to firstly generate all possible 'x' number combinations from an array of 'y' numbers. i.e. combinations of 3 numbers from array(1,2,3,4,5). so... 1,2,3 - 1,2,4 - 1,2,5, 1,3,4 etc I then want to be able to filter out duplicate permutations. i.e. 1,2,3 is the same as 1,3,2. I have googled vigorously but not been able to determine a suitable approach. Any suggestions would be appreciated. Thanks. OK, have no idea what's going on... I've done this a million times... why wont this output!?? I must have a major brain meltdown and dont know it yet!!! Code: [Select] <?php // this echoes just fine: echo $_POST['testfield']; // but this wont echo: echo if (isset($_POST['testfield'])) { $_POST['testfield'] = $test; } echo $test; /// or even this DOESNT echo either!: $_POST['testfield'] = $test; echo $test; ?> Hi All, I'm trying to echo the response from an SLA query, the query works and returns the data when I test it on an SQL application.. but when I run it on my webpage it won't echo the result. Please help? <?php $mysqli = mysqli_connect("removed", "removed", "removed", "removed"); $sql = "SELECT posts.message FROM posts INNER JOIN threads ON posts.pid=threads.firstpost WHERE threads.firstpost='1'"; $result = mysqli_query($mysqli, $sql); echo {$result['message']}; ?> I have a log system that allows 10 logs on each side(Left and right). I am trying to make it so that the left side has the 10 most recent logs, then the right as the next 10. Any ideas? So I need to echo a row from my database with php, but where i need to echo is already inside an echo. This is my part of my code: $con = mysql_connect("$host","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); $result = mysql_query("SELECT * FROM Vendor"); while($row = mysql_fetch_array($result)) { //I need to echo right here .................. but I get a blank page when I try this. Please Help. echo '<option value=$row['vendor_id']>'; echo $row['vendor_id']; echo '</option>'; } mysql_close($con); Result: A Blank page. Thanks in advance! Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. I hope I can explain what is happening. I have created two forms in PHP. The first 'almost' works, i.e. it shows the data. But I have two problems - 1) the second pulldown menu is always empty and 2) $value from the first pulldown menu ALWAYS equals the last entry thus the last 'if' in the function subdomains ($domains) is always called (but still empty). The code may explain this better than me:
<!DOCTYPE html> <html> <body> <!-- processDomains.php is this file - it calls itself (for testing purposes so I can see what is happening) --> <form action="processDomains.php" method="post"> <?php // create the domains array (there are actually several entries in the array but I cut it down for testing) $domains = array (1 => 'Decommission', 'Migration'); echo "Select Domain:"; echo "<br>"; // Make the domain pull-down menu - this displays correctly echo '<select name="domain">'; foreach ($domains as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; // input doesn't matter what is 'submitted', always goes to last $value echo '<input type="submit" name="submit" value="Submit">'; // call function subdomains subdomains ($value); function subdomains ($domains) { // define values for each array - each array contains available choices for the subdomain pulldown menu $migration = array (1 => 'Application Migration', 'Application Patch', 'Application Upgrade'); $decommission = array (1 => 'Applications', 'Servers', 'Storage'); if ($domains === 'Migration') { echo "Select subdomain:"; echo "<br>"; // Make the Migration pull-down menu echo '<select name="migration">'; foreach ($migration as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; } else if ($domains === 'Decommission') { /* === * since 'Decommission' is the last entry in the 'Domains' pulldown list, $value ALWAYS equals * 'Decommission' and $domains equals $value. So this menu SHOULD work but is always * empty. Thus, two problems - the pulldown menu is always empty and $value isn't based * upon user input. */ echo "Select subdomain:"; // this prints so I know I'm in 'Decommission (I eliminated the echo "$domain" to show I'm always coming here)' echo "<br>"; // Make the 'Decommission' pull-down menu echo '<select name="decommission">'; foreach ($decommission as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; echo '<input type="submit" name="submit" value="Submit">' ) // end of 'if-else' } // end of function 'subdomain' ?> </form> </body> </html>Let me say thank you in advance and I appreciate the help! I know I'm doing something (or more than one thing) wrong and I hope someone can tell me what it is. Best Regards! Edited by mac_gyver, 19 January 2015 - 09:37 PM. code tags around posted code please I am writing a script that will parse my PHP classes and check for things like coupling, visualize my objects and connections, dependencies, check for convention usage, etc.
So, I have a simple file upload. I'm never saving the files, just get contents and dump the file and work with the string version.
I'm writing it for me, but I figure I might want to open it for others to use in the future, so I may as well write it that way to begin with -- so I need to validate user input. Problem is, the user input is supposed to be valid PHP code. I'm thinking that, as long as I'm careful, I shouldn't be executing any code contained in strings, but I'm no security expert and I want a warm fuzzy that my thought on this is correct. What kinds of things do I need to look out for? Is it possible to inject when working with strings?
My initial thought is to regex the entire file and replace key portions with known replacements. So ( and ) would become !* and !^ or $ would become @~ (combinations that -- I think -- don't make sense to php?) But that may be completely unnecessary processing time if I'm not in any danger, here. Thanks ahead of time for any help.
PS - as a side question -- what's the best way to verify a file is a php file? I know of getimagesize for images, but should I just check for <? to verify it's php? That seems like it would be too easy to fool -- then again, it might not matter much.
-Adam
I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug Hi 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. 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 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 |