Counting total number of string occurence within a text file

From: Date: Sun, 05 Nov 2000 13:17:09 +0000
Subject: Counting total number of string occurence within a text file
Groups: php.general 
Request: Send a blank email to php-general+get-23783@lists.php.net to get a copy of this message
I have looked up count() and sizeof() but they're not quite what I'm looking for (I think?!) ... I've also looked up substr_count on the annotated manual but unfortunately I'm on PHP3 and no likelihood to have PHP4 for some time. The annotated manual does in fact have a user contributed function outlined as an alternative, but unfortunately it has a bug. Anyway, here's the issue: I'd like to open a text file using PHP, which I know how to do, and count the number of instances of a string, which I don't know how to do! There are in particular 6 types of string. I'd like to count the total of each and use each total to form the data for a graph . 1. Is my methodology correct? ie. opening up the file first and then reading from it? Or is there a more elegant way? 2. How do I count the total number of occurances for each string? Thanks in advance Amir ======= This is the code the totals would be used for ... Obviously, the query above relates to gathering the $totals: HTML> HEAD> TITLE>Test</TITLE> SCRIPT LANGUAGE="JavaScript1.2" SRC="graph.js"></SCRIPT> HEAD> BODY> SCRIPT LANGUAGE="JavaScript1.2"> var g = new Graph(400,300); ?php echo ("g.addRow($total1,$total2,$total3,$total4,$total5,$total6);"); ?> g.scale = 50; g.setXScaleValues("a1", "a2", "a3") g.title = "String Totals"; g.xLabel = "Strings"; g.yLabel = "Total"; g.build(); /SCRIPT> /BODY> /HTML> This is irrelevant to my query, but for anyone interested, I'm using the JavaScript graph builder library at: http://developer.netscape.com/docs/technote/javascript/graph/index.html

« previous php.general (#23783) next »