PHP - Count Characters Of Words In An Array
<?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. Similar TutorialsSay 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? hi, i have a search engine that searches keywords in mysql database... i have a simple form but if someone enters a load of spaces it displays the whole database contents.. also i wanna remove any words less then 3 characters being searched for.. i have (strlen($search)<=3) what else should i add?? cheers 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 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! 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! 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 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, can anyone help me with this. I have a column in my table call "machine", I want to count the number of time each appears and return the results into an array In the example below the number of times each printer appears in the column is returned to the array ____________ machine ____________ fb7500-1 fb7500-2 turbojet turbojet xl1500-1 xl1500-2 canon roland When I run the following I get the names as well as the values and I just want the values?? Result like this Canon 1 FB7500-1 1 Roland 1 TurboJet 2 Vutek QS3200 1 XL1500-1 1 Code: [Select] <?php mysql_connect("localhost","XX","XX"); @mysql_select_db("schedule") or die( "Unable to select database"); date_default_timezone_set('Europe/London'); $query = "SELECT machine, COUNT(machine) FROM maindata GROUP BY machine"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ $array = array( 'key1' => $row[0], 'key2' => $row[1],'key3' => $row[2],'key4' => $row[3], 'key5' => $row[4],'key6' => $row[5],'key7' => $row[6]); extract($array); echo "$key1<br>$key2<br>$key3<br>$key4<br>$key5<br>$key6<br>$key7"; } ?> Code: [Select] $LinksText = array(); for ($i=0; ($i < $cnt && $i < $total); $i++ ) { $Text = explode ('#', $Links[$i]); $LinksText[]=$Text[1]; } $count = count($LinksText); print_r(LinksText); print count($LinksText); if($count > 0){ echo "I am not zero" } else { echo "I am zero" } Code: [Select] output: Array ( [0] => [1] => ) 2 Please tell me why the array count is 2. I have the following array: Code: [Select] Array ( [item0] => Array ( [0] => name1 [1] => name2 [2] => name3 [3] => name4 [4] => name5 )etc... Is it possible to count the number of times a name exists in the compleet array? Thanx in advance! Hey folks! Happy what ever you are celebrating I am trying to limit the number of characters to 200 that this array echos. I have tried a few things... I have tried using "substr($arr_tem, 0, 200)" but obviously it is not working... but I think I am close-ish. Any assistance would be great! Code: [Select] ###print array### echo (implode(", ", array_keys($arr_tem))); Thanks! Hello; I would like to do the following operation; Count duplicate (adjacent) my code
<?php $Array = array("test", "test", "hello", "test", "world", "world", "world", "hello", "test"); for( $i= 0 ; $i <= 6 ;$i++ ) { $j=1; if ($Array[$i] === $Array[$i+1]) { $j+=$j; echo $j; } ?> and showing something like 2,1,1,3,1,1 Thanks Hi all I am trying to loop through an array and output as JSON. What I'm looking to do is create something like: Code: [Select] "something": [ {"title":"Test 1"}, {"title":"Test 2"} ], Notice that the final row has no comma. My code is as follows: <?php foreach($something as $thing): ?> <?php $something_array = array('title'=>$thingt->getId()); ?> <?php echo json_encode($something_array).','."\n"; ?> <?php endforeach; ?> I had to add a comma to the end of the array, or the JSON rows would not be ended with one. How can I get it so that, no matter how many items are in the array, the last row, wil not have the comma at the end? With the comma at the end, my JSON doesn't validate Thanks [/code] HI - I have tried COUNT and array_count _values but they don't do what I want. I have an array of 'quantities' relating to orders. I want to count how many key=>value pairs have a positive value that is to say Not 0 or null or "". So for example array ( shoes=>5, coats=> 3, ties=>0) The answer I seek in this case would be 2 as ties is zero. I don't want to know what the aggregate of the values are or other such info. I have tried looping through with a foreach loop testing for $value > 0 and I failed miserably Any ideas ? Many Thanks ! Hi all, I have an array of data. I am looping through this data to generate a CSV file. However, if there are commas in any of the elements then this will throw out the structure of the CSV file. My question is, how do I loop through the array before I use it to strip out any commas and replace with a space? Thanks for your help. I'm using the code below to on echo certain words based on their index/key value, this works fine however, im trying to only do this in exploded quotes... the problem is, exploding quotes turns the portion into an array which cant be passed to str_word_count... how can i do the same thing only inside quotes. So that hello world "this is a test" would become: Code: [Select] Hello World This [0] => Is [1] => a [2] => Test [3] Im trying to always remove say the 4th word in quotations, or maybe the 3rd and 4th, whatever i want to omit i leave out from the echo, so echo $data[0].' '.$data[3].'; would output "This Test" omitting "Is A" Code: [Select] $data = 'hello world "this is a test"'; $data = str_word_count($data, 1); echo $data[1].' '.$data[2].' '.$data[0]; i HAVE FOLLOWING VALUES IN FEED TABLE
a1a a1b a1c a1d ......
7 8 7 7
8 9 8 8
9 7 7 8
7 8 10 9
6 4 6 7
7 8 8 5
9 7 7 6
This in an array ( select a1a,a1b,a1c,a1d from feed where .....)
1) I want to know how many times each values has occured in the array ( eg: 7 occured 10 times, 8 occured 8 times)
2) How many 7's, 8's, 9's are there in a1a, howmany .....in a1b
Number of times each values occured OVERALL in array as well as also under each head
Please help
I can't get the COUNT of the matching results? Please help. $SomeVar = myname; $queryU = "SELECT * FROM adxone WHERE username = '".$SomeVar."'"; $resultU = mysql_query($queryU); while($scoreP = mysql_fetch_array($resultU)) { $scoreP['roundzAa']; $scoreP['roundzAb']; $scoreP['roundzAc']; $scoreP['roundzAd']; $scoreP['roundzAe']; $scoreP['roundzAf']; $scoreP['roundzAg']; $scoreP['roundzAh']; } $WinV = 'resultA'; $query = "SELECT * FROM acs WHERE resultx = '".$WinV."'"; $result = mysql_query($query); while($scoreUsr = mysql_fetch_array($result)) { $scoreUsr = $scoreM1['winxa']; $scoreUsr = $scoreM1['winxb']; $scoreUsr = $scoreM1['winxc']; $scoreUsr = $scoreM1['winxd']; $scoreUsr = $scoreM1['winxe']; $scoreUsr = $scoreM1['winxf']; $scoreUsr = $scoreM1['winxg']; $scoreUsr = $scoreM1['winxh']; } $count1 = count( array_intersect($resultU, $result) ); echo($count1); mysql_query("UPDATE comp SET id=$count1 WHERE username = '".$SomeVar."'"); ?> Hi guys I'm kinda stuck..so hopefully you guys can lend me a hand I've got an array containing date elements ("Y-m-d")... I'm trying to output some data into googlecharts..so i need to count how many elements that are in the array with todays date -1 day, todays date-2 days...todays date -3days etc... Up until a set number of days (for example 7 days, 14 days etc).. Any advice on how to go about to achieve this? |