stof01 Posted May 14, 2009 Share Posted May 14, 2009 <?php //FORM HAS BEEN SUBMITTED $stop = array("a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also","although","always","am","among", "amongst", "amoungst", "amount", "an", "and", "another", "any","anyhow","anyone","anything","anyway", "anywhere", "are", "around", "as", "at", "back","be","became", "because","become","becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom","but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven","else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own","part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the"); $punc = array(",", ".", "?", "/", ";", ":", "!", "-"); if (isset($_POST['submitted'])) { $words=explode(' ',$_POST['input_text']); if(count($words)<100) { print"<span style ='color:red'>ERROR-You must enter a minimum of 100 words!</span>"; include('form.php'); } else { //BUILD THE CLOUD //remove pun $words=(str_replace ($punc) ' ')); foreach($words as $key => $words) { print $words; } } Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/ Share on other sites More sharing options...
Brian W Posted May 14, 2009 Share Posted May 14, 2009 if you use the code tags around your php or even html snippets, you will likely get more help [ code ]Like this but without the spaces in the tags[ /code ] would be Like this but without the spaces in the tags Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834160 Share on other sites More sharing options...
stof01 Posted May 14, 2009 Author Share Posted May 14, 2009 <?php //FORM HAS BEEN SUBMITTED $stop = array("a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also","although","always","am","among", "amongst", "amoungst", "amount", "an", "and", "another", "any","anyhow","anyone","anything","anyway", "anywhere", "are", "around", "as", "at", "back","be","became", "because","become","becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom","but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven","else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own","part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the"); $punc = array(",", ".", "?", "/", ";", ":", "!", "-"); if (isset($_POST['submitted'])) { $words=explode(' ',$_POST['input_text']); if(count($words)<100) { print"<span style ='color:red'>ERROR-You must enter a minimum of 100 words!</span>"; include('form.php'); } else { //BUILD THE CLOUD //remove pun $words=(str_replace ($punc) ' ')); //count occurences //show top 20 words foreach($words as $key => $words) { print $words; } } This returns a parse error...cant seem to get it Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834166 Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 try this instead $words=str_replace($punc,' '); Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834170 Share on other sites More sharing options...
Brian W Posted May 14, 2009 Share Posted May 14, 2009 it would help if your told us what the error message said... Also, your brackets are not balanced... but that very well could be due to it being only a chunk of your code. Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834171 Share on other sites More sharing options...
Philip Posted May 14, 2009 Share Posted May 14, 2009 $words=(str_replace ($punc) ' ')); Isn't correct syntax. Take a look: str_replace() Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834172 Share on other sites More sharing options...
stof01 Posted May 14, 2009 Author Share Posted May 14, 2009 try this instead $words=str_replace($punc,' '); //// Thanks for the help but now I get Warning: Wrong parameter count for str_replace() in C:\xampp\htdocs\PHP_TEST\cloud\index.php on line 50 Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\PHP_TEST\cloud\index.php on line 63 Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834176 Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 if your wanting to get rid of the punctuation on each word inputed by the user, which is in $_POST['input_text'] then try this code. + ignore what I said before, as that's wrong as well below is the correct syntax for str_replace() <?php //FORM HAS BEEN SUBMITTED $stop = array("a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also","although","always","am","among", "amongst", "amoungst", "amount", "an", "and", "another", "any","anyhow","anyone","anything","anyway", "anywhere", "are", "around", "as", "at", "back","be","became", "because","become","becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom","but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven","else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own","part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the"); $punc = array(",", ".", "?", "/", ";", ":", "!", "-"); if (isset($_POST['submitted'])) { $words=explode(' ',$_POST['input_text']); if(count($words)<100) { print"<span style ='color:red'>ERROR-You must enter a minimum of 100 words!</span>"; include('form.php'); } else { foreach($words as $key => $word) { echo str_replace($punc,' ' ,$word) . '<br />'; } } } ?> Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834181 Share on other sites More sharing options...
stof01 Posted May 14, 2009 Author Share Posted May 14, 2009 Thanks that works great,but how would i use that to get rid of my stop words ?using that function takes the letters out of the words too <?php //FORM HAS BEEN SUBMITTED $stop = array("a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also","although","always","am","among", "amongst", "amoungst", "amount", "an", "and", "another", "any","anyhow","anyone","anything","anyway", "anywhere", "are", "around", "as", "at", "back","be","became", "because","become","becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom","but", "by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail", "do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven","else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only", "onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own","part", "per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via", "was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves", "the"); $punc = array(",", ".", "?", "/", ";", ":", "!", "-"); if (isset($_POST['submitted'])) { $words=explode(' ',$_POST['input_text']); if(count($words)<100) { print"<span style ='color:red'>ERROR-You must enter a minimum of 100 words!</span>"; include('form.php'); } else { foreach($words as $key => $word) { echo str_replace($punc,' ' ,$word) .'<br />'; } Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834190 Share on other sites More sharing options...
JonnoTheDev Posted May 14, 2009 Share Posted May 14, 2009 invalid syntax. you should always check the function manual on php.net for correct usage you cannot pass an array of words into the function as the last parameter only the search & replace so you will have to use per word foreach($words as $key => $word) { $word= str_replace($punc, "", $word); print $word; } Link to comment https://forums.phpfreaks.com/topic/158137-what-is-wrong-with-my-str_replace/#findComment-834192 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.