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?!

Recommended Answers

All 12 Replies

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

Member Avatar for diafol

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);
commented: Was not aware of substr_count function.. Thanks for sharing. +0

Thats great! Thanks ardav

Member Avatar for diafol

OK, solved?

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

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?

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

and

 max_execution_time
Member Avatar for diafol

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?

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.

Member Avatar for diafol

What are you showing me?

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.

Member Avatar for diafol

Ok, just be careful with searching for multibyte characters.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.