0

Hi guys,

For the staticstic purpose I try to write code that will count word "articles" in array in outside file sheet.

$file = "articles";
                $word = count($details[5]($file));
                echo substr_count($word, ' ');

so far, I try somethig like u can see above, but it s not work. any idea why?!

3
Contributors
12
Replies
13
Views
5 Years
Discussion Span
Last Post by diafol
Featured Replies
  • 3
    diafol 3,669   5 Years Ago

    Try $file = "myfile.txt"; $word = "articles"; $content = mb_strtolower(file_get_contents($file), "UTF-8"); echo "Matches for $word in $file : " . substr_count($content,$word); Read More

0

You will probably have to use DOM and get the elements id, like in javascript. I had the same problem in javascript, but i figured it out using jQuery and its simple.

Click Here

3

Try

$file = "myfile.txt";
$word = "articles";
$content = mb_strtolower(file_get_contents($file), "UTF-8");
echo "Matches for $word in $file : " . substr_count($content,$word);
Votes + Comments
Was not aware of substr_count function.. Thanks for sharing.
0

ye, solved.
I m impressed u did it without taking detalis from arrays.
thanks

0

hi guys,
there some problem with this code, no idea why, it s wroking just only with small number of data. when it s comes to procesing with a 1000 lines it s broke. There is mssg:*** Fatal error: Maximum execution time of 30 seconds exceeded in /home/xxx/public_www/xxx on line 87***

$file = "myfile.txt";
$word = "articles";
$content = mb_strtolower(file_get_contents($file), "UTF-8");
echo "Matches for $word in $file : " . substr_count($content,$word);

it s seems like I need completly new code wich handle more data.
any idea?

0

don t worry guys, it s a thing with php.ini file

and

 max_execution_time
0

Even so, shouldn't take 30 seconds. That's a bit extreme. If the text file isn't sensitive, send it over (post it as an attachment) so I can try to replicate the problem.

//EDIT - curious george as I am, tried it with lorem ipsum. I had 17000 paragraphs, each similar to below. There were 500 unique paragraphs repeated 34 times.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vehicula dapibus nulla, et sollicitudin turpis condimentum et. Aliquam dapibus ipsum vel odio tristique bibendum. Integer felis erat, volutpat vel sollicitudin a, mattis vel metus. Duis venenatis, odio at elementum euismod, diam leo dictum mi, quis dignissim velit lorem id tellus. Vivamus nibh sapien, fermentum eu varius eu, lobortis ut dolor. Phasellus laoreet enim faucibus turpis volutpat vitae malesuada nulla bibendum. Nulla facilisi. Sed semper pellentesque sem, ut feugiat quam fermentum sit amet. Donec consequat ultrices gravida. Vestibulum vel lectus ante, sed feugiat lacus. In vitae elit eu nisi pulvinar vulputate. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer fringilla luctus dictum. Mauris eget velit sem. Duis dapibus tincidunt imperdiet. Vestibulum a tortor ac sapien congue consequat non ac turpis.

Ist test for 'lorem' took 3 s (found 13104 hits). I'm on a screwy laptop/Win7. You sure it's the bit of code I supplied? Have you placed it in loop?

Edited by diafol

0

let s try

51.4.190.113 -- [2007-04-01 02:07:04] "GET articles/php_classes_and_oop HTTP/1.0" 200 7674 "MSIE 7.0"
91.73.222.160 -- [2007-04-03 12:42:21] "GET about/vcard HTTP/1.0" 200 4805 "MSIE 7.0"
59.174.170.34 -- [2007-04-03 13:24:42] "GET articles/not/a/page HTTP/1.0" 404 0 "Mozilla/4.

0

It s example of data that I worked with. I solve the problem removing mb_ and 'UTF-8' from the code.

 $content = strtolower(file_get_contents($file));

Thanks for help any way.

Edited by lemur

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.