Bluehost.com Web Hosting $6.95

Counting how many times a word appears in a var?

This is a discussion on Counting how many times a word appears in a var? within the PHP Language forums, part of the PHP Programming Forums category; I've made a small search function as of here: if (stristr($bleh,$search_for)) { if(preg_match('/<title>([^<]*)&...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-26-2006
Advo
 
Posts: n/a
Default Counting how many times a word appears in a var?

I've made a small search function as of here:

if (stristr($bleh,$search_for)) {
if(preg_match('/<title>([^<]*)<\/title>/i', $bleh, $matches))
{
$name = str_replace("./","/",$name);
echo "<li><a href=$link".$name.">".$matches[1]."</a><br><br>";

}


Now this actually works fine, and gives me a page link and title of a
page, based on pages that contain the search term.

Im now trying to rationalise the code a bit more, so that the order of
the links depends on how many times that certain word appears on the
page.

Any ideas please?

My understanding is that i need to somehow count how many times the
$search_for text appears in the $bleh text, and then move onto the next
page.

Reply With Quote
  #2 (permalink)  
Old 10-26-2006
Tyrone Slothrop
 
Posts: n/a
Default Re: Counting how many times a word appears in a var?

On 26 Oct 2006 02:41:00 -0700, "Advo" <max_mischief@hotmail.com>
wrote:

>I've made a small search function as of here:
>
>if (stristr($bleh,$search_for)) {
> if(preg_match('/<title>([^<]*)<\/title>/i', $bleh, $matches))
>{
> $name = str_replace("./","/",$name);
> echo "<li><a href=$link".$name.">".$matches[1]."</a><br><br>";
>
> }
>
>
>Now this actually works fine, and gives me a page link and title of a
>page, based on pages that contain the search term.
>
>Im now trying to rationalise the code a bit more, so that the order of
>the links depends on how many times that certain word appears on the
>page.
>
>Any ideas please?
>
>My understanding is that i need to somehow count how many times the
>$search_for text appears in the $bleh text, and then move onto the next
>page.


http://us2.php.net/manual/en/function.substr-count.php
Reply With Quote
  #3 (permalink)  
Old 10-26-2006
Erwin Moller
 
Posts: n/a
Default Re: Counting how many times a word appears in a var?

Tyrone Slothrop wrote:

> On 26 Oct 2006 02:41:00 -0700, "Advo" <max_mischief@hotmail.com>
> wrote:
>
>>I've made a small search function as of here:
>>
>>if (stristr($bleh,$search_for)) {
>>if(preg_match('/<title>([^<]*)<\/title>/i', $bleh, $matches))
>>{
>>$name = str_replace("./","/",$name);
>>echo "<li><a href=$link".$name.">".$matches[1]."</a><br><br>";
>>
>>}
>>
>>
>>Now this actually works fine, and gives me a page link and title of a
>>page, based on pages that contain the search term.
>>
>>Im now trying to rationalise the code a bit more, so that the order of
>>the links depends on how many times that certain word appears on the
>>page.
>>
>>Any ideas please?
>>
>>My understanding is that i need to somehow count how many times the
>>$search_for text appears in the $bleh text, and then move onto the next
>>page.

>
> http://us2.php.net/manual/en/function.substr-count.php


Oh Tyrone, that guy is having a great time with regex, and now you spoiled
all the fun with an easy ready-to-go built-in function. :P

Erwin
Reply With Quote
  #4 (permalink)  
Old 10-26-2006
Advo
 
Posts: n/a
Default Re: Counting how many times a word appears in a var?


Erwin Moller wrote:
> Tyrone Slothrop wrote:
>
> > On 26 Oct 2006 02:41:00 -0700, "Advo" <max_mischief@hotmail.com>
> > wrote:
> >
> >>I've made a small search function as of here:
> >>
> >>if (stristr($bleh,$search_for)) {
> >>if(preg_match('/<title>([^<]*)<\/title>/i', $bleh, $matches))
> >>{
> >>$name = str_replace("./","/",$name);
> >>echo "<li><a href=$link".$name.">".$matches[1]."</a><br><br>";
> >>
> >>}
> >>
> >>
> >>Now this actually works fine, and gives me a page link and title of a
> >>page, based on pages that contain the search term.
> >>
> >>Im now trying to rationalise the code a bit more, so that the order of
> >>the links depends on how many times that certain word appears on the
> >>page.
> >>
> >>Any ideas please?
> >>
> >>My understanding is that i need to somehow count how many times the
> >>$search_for text appears in the $bleh text, and then move onto the next
> >>page.

> >
> > http://us2.php.net/manual/en/function.substr-count.php

>
> Oh Tyrone, that guy is having a great time with regex, and now you spoiled
> all the fun with an easy ready-to-go built-in function. :P
>
> Erwin


err no.. what he gave me does aditional tasks to what the code i pasted
does. the code i pasted also works 100% as expected, and as needed.

the code i am after and looking towards will add to this existing code,
not replace it. thanks then

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:27 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0