Webmaster Chronic Blog » PHP https://www.webmasterchronic.com Giving You the Good Stuff Since 2k9 Fri, 12 Mar 2010 20:03:23 +0000 http://wordpress.org/?v=2.8.4 en hourly 1 Word Count, Syllable Count, Sentence Count, Flesch Reading Ease Score, etc. https://www.webmasterchronic.com/code/snippets/php/word-count-syllable-count-sentence-count-flesch-reading-ease-score-etc/ https://www.webmasterchronic.com/code/snippets/php/word-count-syllable-count-sentence-count-flesch-reading-ease-score-etc/#comments Thu, 10 Dec 2009 08:37:45 +0000 kpaul https://www.webmasterchronic.com/?p=520 I forget where exactly I lifted these from, but they’ve been very useful for some coding projects I’ve been working on silently in the background.

Maths and English

Maths and English

I thought I would share them here. Enjoy and use responsibly.

Maths and english, boys, maths and english…

// Number of words: number of space series or linebreaks + 1
$wc = preg_match_all( '/[ \r]/', preg_replace( '/ +/', ' ', $mynewtext), $tmp );
// Number of syllables: vowels not followed by another vowel. Quite accurate approximation.
$syc = preg_match_all( '/[aeiouy][^aeiouy]/', $mynewtext, $tmp );
// Number of polysyllabic words (>=3 syllables): Vowel, non-spaces, vowel, non-spaces, vowel (or more non-spaces-vowel)
$psyc = preg_match_all( '/[aeiouy]([^ ]*[aeiouy]){2,}/', $mynewtext, $tmp );
// Number of sentences: Number of periods, exclamation marks, question marks and linebreaks
$sec = preg_match_all( '/[.!?\r]/', $mynewtext, $tmp );
// Flesch Reading Ease Score
$fres = 206.835 - 1.015 * ( $wc / $sec ) - 84.6 * ( $syc / $wc );
// Simple Measure of Gobbledygook
$smog = 1.043 * sqrt( $psyc * ( 30 / $sec ) ) + 3.1291;
Share/Bookmark]]>
https://www.webmasterchronic.com/code/snippets/php/word-count-syllable-count-sentence-count-flesch-reading-ease-score-etc/feed/ 2
Quick and Dirty CSV to RSS/XML for WordPress Import… https://www.webmasterchronic.com/code/snippets/quick-and-dirty-csv-to-rssxml-for-wordpress-import/ https://www.webmasterchronic.com/code/snippets/quick-and-dirty-csv-to-rssxml-for-wordpress-import/#comments Tue, 01 Dec 2009 10:21:14 +0000 kpaul https://www.webmasterchronic.com/?p=331 After running, you can view the source and save the output to an XML file that you can import into WP. Nothing fancy, but thought it might help one or two ppl… It is set-up to date the posts every 12 hours, although this is easily changed…

<?php
function get_csv($filename, $delim=',')
{
   $row = 0;
   $dump = array();

   $f = fopen ($filename,"r");
   $size = filesize($filename)+1;
   while ($data = fgetcsv($f, $size, $delim)) {
       $dump[$row] = $data;
       $row++;
   }
   fclose ($f);

   return $dump;
}

$myfile = "123.csv";
$xxx=0;
$mywritefile = "";

$test = get_csv($myfile);

foreach ($test as $mthis) {
$xxx++;
$hourcount = ($xxx * 12);
$mincount = (12 * $xxx);
$futuredate = mktime(date("h")+$hourcount,date("i")+$mincount,date("s")+$mincount,date("m"),date("d"),date("Y"));

$mypubdate = date("D, d M Y h:i:s A",$futuredate);

$mywritefile .= "<item>\n";
$mywritefile .= "<title>".$mthis[0]."</title>\n";
$mywritefile .= "<category>Your Category Tag</category>\n";
$mywritefile .= "<content:encoded>".$mthis[1]."<br />".$mthis[2]."<br />".$mthis[3]."<br />".$mthis[4]."</content:encoded>\n";
$mywritefile .= "<pubDate>".$mypubdate."</pubDate>\n";
$mywritefile .= "</item>\n\n\n";

}

echo $mywritefile;

?>
My Kind of Woman

My Kind of Woman

Share/Bookmark]]>
https://www.webmasterchronic.com/code/snippets/quick-and-dirty-csv-to-rssxml-for-wordpress-import/feed/ 0