Jump to content

richardjh

Members
  • Posts

    74
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

richardjh's Achievements

Member

Member (2/5)

0

Reputation

  1. Thank you for the quick replies and help. I found that these three lines seem to be doing what I want: $word1 = preg_replace('/\s+/', ' ', $text); $word = explode(' ', $word1); $words = count($word); Using this I can put any amount of white space between words and the count remains the same (which I want). I will test it a bit more though before getting my hopes up.
  2. Yeah, I've used that as well and combinations of all those functions but so far I've not clinched it.
  3. I've been trying to come up with a way to accurately count a word string which includes punctuation marks. I've got close but the white-space is causing a problem. I have used a couple of functions such as str_replace and explode and I can now get an accurate count for texts with most punctuation and 'normal' white space. BUT.. If I put in three extra spaces between words the count adds 1 to the total. $words2 = str_replace("-", "", $string); // strips a hypen $words3 = str_replace(' ', ' ', $words2); // strips double spaces $words = explode(' ', $words3); This is obviously NOT a script - rather a string of text being passed through three functions to cleanse it. But as you can see it will strip two white spaces when they occur but no more. So three, four, five etc. will be counted as extra words. What else could I try to give me an accurate count? I am very raw at php. :'( thanks Richard
  4. Well I'm thinking of creating something to analyze blocks of text such as short stories and chapters of books. For pace I thought that by counting the sentences in a block of text AND by working out how many short, long or average sentences (including in the calculation things such as dialogue - text within quotes) and other factors, the script should arrive at a figure which could give a guide on pace within that block of text. For instance lots of short sentences with few long/average sentences would indicate pace which is far too fast; or a block with only very long sentences would be far too slow etc. Obviously the maths and calculations for such a script would be complicated and have to take in quite a few factors but that's the gist.
  5. the autocrit site I linked to above - could this all be achieved using php Neil? thanks for the remarkably quick reply too
  6. Okay, maybe i should rephrase the question would it be possible to create a php script which could analyze, say, a paragraph of text and return a list of things such as word frequency, common word / unusual word / overused words (maybe using a dictionary via mysql). sentence length and so forth? I know php has many string manipulation functions but I'm wondering how clever one could be using php to analyze long strings. I think it would be possible to also create a php code snippet to analyze the pace of a block of text by getting it to count the sentences ( increment +1 at each full stop) and then by using a bit of math calculations work out if the block of text is fast or slow paced (maybe also using speech mark counts within the calculations). Anyone have a view on this? many thanks thanks R
  7. Hope it's okay to post this question here: Would php be capable of text string manipulations such as on this site: http://www.autocrit.com/pages.php?pageid=59 moreover, would it be possible to create a grammar/syntax checker using php? thanks for your replies. R
  8. This is a follow on from a thread I posted for help but alas I'm still stuck so I'm struggling through bit by bit myself. Could someone advise me how I can split a string of words (sentence) into separate words to place into an Array and then place each array element into a mysql table? I've tried and tried to do it myself and failed miserably! I really need an expert. thanks and sorry for being a pest R
  9. Can anyone offer any advice on this please?
  10. I have a feeling it's something to do with this line $query_value = "(" . implode("'),('",$new) . "')";
  11. I've been pottering and I decided to echo the output for the above code and this is what I get: If I add the tag words... 'this, is, a, string' (no surrounding quotes) I get as the echo: (this'),('is'),('a'),('string') (') Should this be the expected output? and what about the first word - it lacks an beginning apostrophe? Should this output be surrounded by brackets and/or appostrophes? The query needs to be just the four words (in this case) which are checked and added to the tags2 table OR (if they already exist in the tags2 table) incremented by +1 hope someone can help R
  12. ok! However I'm still trying to make this code work. Like I said I get no errors and table 1 updates and/or inserts correctly. I just can't seem to communicate with table 2 using this code. I'll post the full code of what I have: function Update($sid, $taglist) { include("../cfig.php"); // sanitize $taglist $taglist = mysql_real_escape_string($taglist); $taglist = strtolower($taglist); // coverts string to lowercase $taglist = trim($taglist); // trims white space $taglist = str_replace(", ", "-", $taglist); // replaces space in between words with a dash $taglist = str_replace(" ", "+", $taglist); // replaces space in between words with a dash $taglist = str_replace("'", "", $taglist); // replaces space in between words with a dash // aschk's code start // My String to work with. $mystring = $taglist; // My String as an array. $values = explode("-", $mystring); // The SQL Query value for my string. $query_value = "'" . implode("','", $values) . "'"; // SQL query. $query = "SELECT * FROM tags WHERE tag IN (%s)"; // Execute Query. $result = mysql_query(sprintf($query, $query_value)); // Create data array. $data = array(); while($row = mysql_fetch_assoc($result)){ $data[] = $row['tag']; } // Insert new values. $new = array_diff($values, $data); $query_value = "(" . implode("'),('",$new) . "')"; $result = mysql_query(sprintf("INSERT INTO tags(tag) VALUES %s", $query_value)); // Update old count values by 1. $old = array_intersect($values, $data); $query_value = "(". implode("'),('", $old) . "')"; $result = mysql_query(sprintf("UPDATE tags SET count = count+1 WHERE tag IN %s", $query_value)); // aschk's code end // code for update/insert of 1st tag table called (tags2) $add_taglinks = "SELECT * FROM tags2 WHERE sid='$sid'"; $add_result = mysql_query($add_taglinks) or die(mysql_error()); if(mysql_num_rows($add_result) < 1) { $result = mysql_query("insert into tags2 values ('', '$sid', '$taglist')", $db); if(!$result) { echo (mysql_error()); } else { echo "<p><center><b>Thank You.</b><br>The Tags are now in place for this book <a href=\"/expand.php?sid=$sid\">HERE</a><p>"; } } else { $query2 = "UPDATE tags2 SET tag_list='$taglist' WHERE sid='$sid'"; $result2 = mysql_query($query2) or die(mysql_error()); echo "<p><center><b>Thank You.</b><br>The Tag List has been updated for this book <a href=\"/expand.php?sid=$sid\">HERE</a><p>"; } } Again thanks for the help and advice R
  13. Excellent thanks for that. I've added your code aschk and although the first table still updates the 2nd table (which this added code is for) still doesn't add or update. This is what I have so far: $mystring = $taglist; // My String as an array. $values = explode("-", $mystring); // The SQL Query value for my string. $query_value = "'" . implode("','", $values) . "'"; // SQL query. $query = "SELECT * FROM tags WHERE tag IN (%s)"; // Execute Query. $result = mysql_query(sprintf($query, $query_value)); // Create data array. $data = array(); while($row = mysql_fetch_assoc($result)){ $data[] = $row['tag']; } // Insert new values. $new = array_diff($values, $data); $query_value = "(" . implode("'),('",$new) . "')"; $result = mysql_query(sprintf("INSERT INTO tags(tag) VALUES %s", $query_value)); // Update old count values by 1. $old = array_intersect($values, $data); $query_value = "(". implode("'),('", $old) . "')"; $result = mysql_query(sprintf("UPDATE tags SET count = count+1 WHERE tag IN %s", $query_value)); // end the 2nd table is called 'tags' and it has three columns - 'id'(auto increment) 'tag' and 'count'. The variable '$taglist' is the list of words the users has imput via a one line text box. The $taglist is added to the FIRST table successfully in the correct format (i.e the-string-of-tags) but so far the 2nd table remains unchanged. There are a few lines in your code aschk that i don't understand simply because I'm a novice php'er. If when we can get this bit of code to work correctly I will ask you what the various bits mean e'g' $query = "SELECT * FROM tags WHERE tag IN (%s)"; what does %s mean? thanks for your valued help. R
  14. But how would I form the if statement to query the database with the information in the Array?
  15. Hello again I have create a simple script which will add a string of tagwords to a mysql database table . This works fine but I want to also do the following with the tagword string... 1) I want to exlode the string (e.g this-is-a-string) into an array of separate words without the dash between)(e.g Array ( [0] => this [1] => is [2] => a [3] => string ) Then I want to check another mysql table to see if any of these words have a row. The ones that DON't have a row in the table I want to add them and auto increment the 'id'. If the DO have a row I simply want to increment the 'id'. Could some one give me some idea how to do this please? I have tried but got as far as 'explode' and then couldn't work out how to query the database table etc. thanks for any help. R
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.