PHP - Look For Certain Words From Array List Within A String
Hello,
I'm having trouble getting a piece of code to work and as a result right now i have bloated code on a simple task. Currently my code looks like this: Code: [Select] //convert responses into one string to check for spam $full_string = $name.' | '.$email.' | '.$message; //look for spam words if ( (stristr($full_string, 'test')) || (stristr($full_string, 'http')) || (stristr($full_string, 'www')) || (stristr($full_string, 'site')) || (stristr($full_string, 'fake')) || (stristr($full_string, 'viagra')) || (stristr($full_string, 'cialis')) || (stristr($full_string, 'asdf')) || (stristr($full_string, 'txt')) || (stristr($full_string, 'doc')) || (stristr($full_string, 'xls')) || (stristr($full_string, 'htm')) || (stristr($full_string, 'sale')) || (stristr($full_string, 'free')) ){ I would like to instead place all my 'spam' words in an array like this Code: [Select] $spam_array = array('test', 'viagra', cialis...etc If i had all my spam words in an array, how would i write an if statement to check if any of those words appeared in $full_string ? Thanks for your help! Similar TutorialsHello, I am EXTREMELY new to PHP, and coding in general. I have attempted to search for an answer to this already, but I'm not sure I'm using terminology that will lead me to an solution, as I haven't come up with much. I'm hoping that someone can provide some assistance, or at least point me in the right direction for some reading. What I am trying to do it search a string for a match to any of 12 words. I'm wondering if there is a smarter way to do this than coding 12 different lines, each one looking for a specific word. If you can point me in the right direction, then thank you very much =) Dead simple, I know it is but I'm still a little newbie. I have this chat box, and I don't want people to be able to swear in it so I need help making a function where you call the string as an argument and it returns true if the string has any words from an array in it, Even if the word is walking and not just walk. If it's true I can replace the entire string with something else. Can someone tell me what functions I need? I prefer you didn't do it all for me I need to learn Thanks in advance! I want to check if a string has any of words listed in array; Code: [Select] $array=array('word1', 'word2', 'word3'); $string="This is a sentence containing word2"; Now I want to make an 'if else' to check if the string contains any of the words listed in the array. Thanks hello, i seem to be stuck again and this bug is difficult for me to solve.
if(isset($_POST['boards'])) $boards[] = $_POST['boards']; $allboards = implode("",$boards[0]); echo $allboards;outputs (browser source)... hello world I have a combobox with the "multiple" property. when two items are selected, the combobox "name" property has an array that passes to the $_POST variable. what i would like is those two words to be displayed on the same line. I have tried rtrim($var, "\r\n") but that does nothing. the reason i need them on the same line is because i would change then to "hello, world" and then add them as a mysql query, for example... $query = "SELECT hello, world FROM table... This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 I can't seem to find a decent code function to search for "curse" words that i would deem inappropriate in an array. Count the number of instances the function finds a curse word and then if the number is greater than one halt the script. something like the following but not really.... Code: [Select] $words = array('ass','fuck','shit'); $string = 'Blah blah blah ass blah blah fuck blah blah shit!'; //code to count the instances of the curse words(3) if($instances > 0) { echo "no cursing please."; } ; any help on how to do this would be much appreciated! Hello again to all I would like to ask if how can i removed the first 3 words on this string? Quote Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque hendrerit accumsan turpis, vitae rutrum quam cursus id. Sed quis pulvinar eros. Integer vel tellus turpis. Donec tortor dolor, convallis in mollis et, rhoncus eu lacus. Etiam quam risus, fringilla ac tempor in, congue vel felis. Mauris eu luctus augue. Fusce nisl neque, convallis a posuere a, ultricies et metus. thanks in advance hi folks, i have a variable in which some common words are stored and another variable in which a sentence is stored. I want to remove the common words from the sentence> Is there any way of doing this in PHP? Code: [Select] <?php $common_words = "to, this, all, the, from"; $sentence = "I want to remove all the common words from this sentence"; ?>the final output should be: "I remove common words sentence." Hi, how can I match two keywords in a string? eg. if keywords (Kids,Hoody) are in this string (Animal Kids Basic Hoody Blue) do something..... Thanks. I have a string in the form of "word1-word2-word3-word4-word5-word-6-word7", but I want to shorten it to 5 words only. I have a situation where I need to put a textbox and a submit button on a page. The user is logged in. The script needs to check against a list of words to make sure the word the user entered is correct and if so submit their information(ie:name, email, time, date, word entered to a database table. The part i'm having trouble with is figuring out how to make it check against a specific set of words. Code: [Select] <p><strong>Enter Word</strong></p> <form action="/paradisepassword.php" method="post"> <input type="hidden" name="action" value="password2paradise" /> <table cellpadding="5px"> <tr> <td style="padding:3px;"><label for="password2paradise">Enter he :</label></td> <td style="padding:3px;"><input name="password2paradise" type="password2paradise" id="password2paradise" value="" maxlength="30" tabindex="5" /></td> </tr> <tr> <td style="padding:3px;"> </td> <td style="padding:3px;"><input name="submit" type="submit" value="Submit Password" tabindex="7" class="generalButton" /></td> </tr> </table> </form> and the php file to process it: <?php include_once($_SERVER['DOCUMENT_ROOT']."/_core/config.php"); include_once($_SERVER['DOCUMENT_ROOT']."/_core/db-connect.php"); include_once($_SERVER['DOCUMENT_ROOT']."/_core/functions.php"); include_once($_SERVER['DOCUMENT_ROOT']."/_core/user-cookies.php"); ///////////////////////////////////////////////////////////////////////////// //function submitParadisePassword($intContestantID, $intDateSent, $intParadisePassword, $strType){ $paradise_password = paradisePassword("password1", "password2", "password3", "password4", "password5", "password6", "password7", "password8", "password9", "password10"); if (!$paradise_password == paradisePassword); { // success! $query_insert="INSERT INTO ".DB_DATABASE.".paradisepassword_2010 ( accountID, nickname, firstName, lastName, email, paradisePassword, sentFromUrl, dateSent, dateSentTimestamp, ipAddress ) VALUES ( '".mysql_real_escape_string($_POST['accountID'])."', '".mysql_real_escape_string($_POST['nickname'])."', '".mysql_real_escape_string($_POST['firstName'])."', '".mysql_real_escape_string($_POST['lastName'])."', '".mysql_real_escape_string($_POST['email'])."', '".mysql_real_escape_string($_POST['paradisePassword'])."', '".mysql_real_escape_string($_POST['sentFromUrl'])."', '".date("Y-m-d")."', '".time()."', '".$_SERVER['REMOTE_ADDR']."' ) "; mysql_query($query_insert); header("Location: ".$_POST['sentFromUrl']."?p2p=success"); } else { header("Location: ".$_POST['sentFromUrl']."?p2p=fail"); } //} ?> what am i missing? hi every1 im driveing crazy with this... i have a database with a field with descriptions of products named "DESCRIP" in the main page i have a text field where user write the words to search for i wanrt make an "SELECT * FROM models where descrip like xxx OR descrip like xxx... bla bla bla" i wrote this code but send me an error... waht can be wrong??? $word='"SELECT * FROM models WHERE descrip LIKE ' ."'"; $srched=$_POST['words']; $pieces = explode(" ", $srched); $all=count($pieces)-1; for($i=0;$i<=$all;$i ++) { $word = $pieces[$i] ."'"; if($i!=$all) { $word .= $word . ' OR descrip like ' . "'"; } else { $word .= $word .'"' . ";"; } } $colname=$word; mysql_select_db($database_zero1, $zero1); $query_srch = $colname; $buscar = mysql_query($query_srch, $zero1) or die(mysql_error()); $row_srch = mysql_fetch_assoc($srch); $totalRows_srch = mysql_num_rows($srch); tnx in advcd <?php $title = "This is an example of a sentence in a paragraph"; $title_array = explode(" ", $title); $count = strlen($title_array[0]); ?> what i want to do is store the count for every characters of every word in the array using a loop e.g the count will be stored in a variable $chr_count then when i access the count for "This" it should be like this $chr_count[0]=4, $char_count[1]=2 etc. Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> Hi, I use the following code to create a select menu from an array of options stored in LISTS.php: include 'LISTS.php'; print('<select id="from" name="from">'); foreach ($langList as $lang) {printf('<option %s>%s</option>', ($from1 == $lang ? 'selected="selected"' : ''), $lang); } echo '</select>'; where LISTS.php includes the following: $langList = array(' ','English', 'French', 'German', 'Dutch', 'Spanish'); This works great, but now I want to do something similar with a checkbox list, where each checkbox has an associated 'onchange' javascript function and I'm getting pretty stuck. My checkbox list is of the following form: Code: [Select] <html> <ul style="height: 95px; overflow: auto; width: 200px; border: 1px solid #480091; list-style-type: none; margin: 0; padding: 0;"> <li id="li1b"><label for="chk1b"><input name="chk1b" id="chk1b" type="checkbox" onchange="function1('chk1b','li1b')">Option1</label></li> <li id="li2b"><label for="chk2b"><input name="chk2b" id="chk2b" type="checkbox" onchange="function1('chk2b','li2b')">Option2</label></li> //etc. </ul> </html> What I want to do is have 'Option1', 'Option2', etc. stored in an array in LISTS.php and have a PHP script that populates the checkbox list accordingly, in a similar manner to my select menu above. I can't work out how to get the ID of the next <li> and the next <input> in the list to go up by one each time, e.g. 'li1b' then 'li2b', 'li3b', etc. Could someone pls help me out? Thanks! Say I have this array: Code: [Select] array( 0 => time 1 => time 2 => to 3 => to 4 => to 5 => fly ); and 2 variables - $occMin and $occMax as number of occurrences. If: Code: [Select] $occMin = 2; $occMax = 3; I want to produce sorted list with most occurrences at the top: Code: [Select] array( 0 => array('to', 3), 1 => array('time', 2) ); My face just melted at the thought of even beginning to tackle this. Is this somewhat possible? would it require a monster function or am I missing some native php functions which could lend a hand? So I'm trying to create an Array from a comma separated string containing array{s}. How can I take a string full of comma separated hex values such as : <?php $myStr = ( "00ffff", "00cccc", "009999", "007777", "004444", "001111", "01ffff", "01cccc", "019999" ); ?> & turn it into 3 separated arrays like : <?php $myNewArrs = [ Array1 ( 3 ), Array2 ( 3 ), Array3 ( 3 ), ]; ?> which REALLY looks like : <?php $myNewArrs = [ Array ( "00ffff", "00cccc", "009999" ), Array ( "007777", "004444", "001111" ), Array ( "01ffff", "01cccc", "019999" ), ]; ?>
? Thank you & have a great afternoon!
Edited May 27 by AquariaXI Can anyone help me output "Zinfandel|Sauvignon Blanc" from "This very nice wine is produced in California and is made from Zinfandel and Sauvignon Blanc grapes."?
Please also notice the case insensitivity. I prefer the output with capitals on first words.
I created the following code :
<?php $ds = "Riesling|Sauvignon Blanc|Zinfandel|Muscat/i"; $string = "This very nice wine is produced in California and is made from zinfandel and Sauvignon Blanc grapes."; echo "This is the string to extract the grapes from : "; echo $string; echo "<br>"; echo "These are the grapes that need to be matched in a regular expression : "; echo $ds; echo "<br>"; $matches = array(); $search = preg_match_all($ds, $string, $matches); foreach ($matches[1] as $match) { echo $match; // I want this to output "Zinfandel|Sauvignon Blanc" with a pipeline between the matches } ?>Any help pretty much appreaciated! I need to pass captured data, basically, a list of email addresses that are being read from a CSV file and (1st) saved to an local database, then sent over to an external source via URL string. I have everything working except - script opens the file, read and validates all emails in the specified column, and saves to local db. ISSUE: after validating then INSERTING the data into local mySQL db, I need to then pass each piece of data to an external source via URL string. Example: www.domain.com?email={$new_email} I was initially think to just add the URL in a header function but, I'm not sure if the HEADER() function the right method to pass all of the data - during the loop - via the URL string. For example, if the CSV file contain 500 emails: Q: how can I continue that loop until the last email read, passing each up to the external source via the URL string? I'm not sure if using the HEADER() function at the end of the script - but within the loop - will interate and send each capture email via that URL string. Can anyone advise a possible solution to this? thanks OK so here is what I want to do. I have a bunch of strings stored in a table. The strings are like this grandparent.parent.child. some are just parent.child What I want to do is Select all and then put them into an array. soooo x.y.z would become $Var['x']['y']['z'] and a.b would become $Var['a']['b'] It has to be dynamic because some strings are just 2 levels, and it goes all the way up to 6 levels. I have different plans for setting the variably to something but I can handle that. Any ideas? |