PHP - Counting Certain Words In A String
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! Similar TutorialsSorry if this is very basic. We have our church membership lists in a MySQL database with the following fields: Surname Person1 Person1_Membership Person2 Person2_Membership ... The membership fields will either be empty or contain "Resident" or "Non-Resident". The reason for two columns is that some couples may only have one partner as a member. I am trying (without success) to find a way of getting a total (to display on a web page) of how many "Resident" and how many "Non-Resident" members we have. In other words, I'm trying to get a sum of the total number of times "Resident" and and total number of times "Non-Resident" appears in the two columns combined. (hope that makes sense!) I would appreciate any pointers from anyone who has managed to do this, or something similar, already. Many thanks for the help This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 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. 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'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! Hello, 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 =) 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. 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... Hi im trying to make it so the time says how many hows left, not how many hours past. i have the right idea but it shows a negative number under "$time" $hours = number_format(($diffrence / 60 / 60)); $time = number_format(($hours - 24)); I have a table in my database named order, and i want to count the quantity sold. i have the basic query already setup like: Code: [Select] $sql = "SELECT SQL_CALC_FOUND_ROWS deal.id, deal.title, deal.min_qty, deal.start_date, deal.end_date, deal.status, deal.secondary, count(o.id) as orders_cnt FROM deals as deal LEFT JOIN orders as o on o.d_id = deal.id WHERE start_date >= '".$beg."' AND start_date <= '".$end."' GROUP BY o.d_id, deal.id ORDER BY start_date LIMIT ".AwsPager::getCurrentIndex().", ".AwsPager::getLimit(); Which would theoretically work, but in the orders table, there is a column named quantity, and its those numbers that i need to add together and store in the array as orders_cnt.. any clue how i can do that? Hiya peeps, I have a mysql database with a record of all the images a customer uploads on my site, these images are displayed on there account. I can get this to work but the problem I'm facing is I need a minimum of 5 images displayed so if they only upload 2 images for instance I need to detect that and add my "No Image Uploaded" image. But if they have uploaded 5 or more I need to just let them be displayed without adding the "No Image Uploaded" picture. Does anyone have any ideas as I'm very stuck! Many thanks James. I have an array. When I print it it looks like this: Quote Array ( [1] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [Button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 2 [WeltSize] => [SKU] => c-111111 [Edge] => Knife [Cap] => N [Straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 108.5 ) [2] => Array ( [Cushion] => Cushion 1 [Fabric] => f-111111 [FabricPrice] => 0 [Fill] => Fiber [Button] => none [ContWelt] => none [ContWeltFabric] => none [Zipper] => N [Quantity] => 4 [WeltSize] => [SKU] => c-111111 [Edge] => Knife [Cap] => N [Straps] => N [Hinged] => N [Type] => Boxed Button [Price] => 54.25 [Total] => 217 ) ) Now when I use count() I get a result of 01 when I should get 02 when I use count( ,1) I get a result of 381. I am Using this wrong? the array is stored in $_SESSION['cushArray'] One more question to ask. I'm trying to do a count of total logins that have happened in the last 5 months including the current one so far. My users_logins table has the following structu users_id, session_id, login_date(datetime), last_activity(datetime). What the end result is going to be is: <tr> <td></td> <th scope="col"><?php echo date("M", strtotime("-4 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-3 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-2 month")); ?></th> <th scope="col"><?php echo date("M", strtotime("-1 month")); ?></th> <th scope="col"><?php echo date("M"); ?></th> </tr> <tr> <th scope="row">Logins</th> <td>94</td> <td>53</td> <td>124</td> <td>92</td> <td>105</td> </tr> Where the first td would be May and the last td would be September. Do I have to do this in 4 separate queries. If so here's what I have for the first query. I'm not sure what woudl go for the WHERE. $four_months_ago_query = "SELCT COUNT(date_login) FROM users_logins WHERE ? "; I am getting the result I expected with ORDER BY/GROUP BY queries WITH a troubling EXCEPTION: the data is being IN ORDER from 0 thru 9, but 10 (which in this test sample is my LARGEST quantity) is being inserted between the ONE and 2 quantity. Not sure if this will occur with ALL teen values, as well as hundreds. The column is a SMALLINT field (not sure if that makes a difference)> Is there a solution for this situation? I'm trying to get a total number from the db where the month is the same and the ip is different. This is a stats script that someone else wrote, and I'm just trying to get a month-to-month total. Right now, it pulls the information out and displays the month with how many different ips came that month, the problem is, it lists like this: June - 41 - 41 June - 1 - 1 June - 1 - 1 June - 1 - 1 June - 1 - 1 June - 1 - 1 June - 9 - 9 June - 2 - 2 June - 2 - 2 June - 2 - 2 June - 1 - 1 June - 3 - 3 June - 2 - 2 June - 4 - 4 June - 1 - 1 June - 13 - 13 June - 154 - 154 what I need to do is grab all those numbers and give a total for that month, in this case, June. This is my query Code: [Select] $query = "SELECT date, COUNT(referrer)'referrer' FROM app_analytics WHERE appid = $userid AND date BETWEEN '" .$y_month . "' AND '" . $t_month . "' GROUP BY referrer ORDER BY date"; Can anybody help out? Thanks in advance I know how to count the files: <?php $dir = $_SERVER[DOCUMENT_ROOT]."/api/sigs/cache/".$i[id]."/"; $files = scandir($dir); $result = count($files); printf("$result Signatures Generated"); ?> But i'm trying to make it so it only counts the files that were modified recently (That Day). I have a page that displays a list of retail locations (est. 100-150 locations). I have my layout setup to fit 3 columns side by side. Ex: <div class="col"></div> <div class="col"></div> <div class="col"></div> .. with the "col" class having a specific width and float: left. Basically, I want to print out the locations in the column and when a column reaches a certain number of locations, it closes that div and starts a new one and continues printing the rest of the locations. How would I go about making sure that once a column has reached a certain number of locations, it closes the div and starts the new one? |