Hi there, hope this solution is of help to you:
http://www.experts-exchang
As they discuss how to count the number of occurrences in a string.
Goodluck!
Main Topics
Browse All TopicsHi - I am struggling to get this to work with my current code.
Please see http://70.87.107.194/~g3cr
I am trying to add code in line 105, 107 and 109 AND in 248, 251, 254, 257, 260, 263
that would display the frequency of times the keyword Phrase entered as the variable "keyword" appears between the <H1>, <b>, and <body> tags.
I was provided with the following 2 solutions earlier but I could not make either work (I just don't know how to add their code to my code to make it go...)
Help would be very, very much appreciated....
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi there, hope this solution is of help to you:
http://www.experts-exchang
As they discuss how to count the number of occurrences in a string.
Goodluck!
Give this a try also replace in your script from where it starts here
<?php for($i=0;$i<count($urlarray
//
usleep(5000000);
$url_content = file_get_contents_curl($ur
$words_h1 = "0";
$words_b = "0";
$words_body = "0";
$keywords_counth1 = "0";
$keywords_countb = "0";
$keywords_countbody = "0";
preg_match_all("%<h1>[\w\s]*
preg_match_al
preg_match_all
$count = (count($allh1match['0']) > (count($allbmatch['0']))) ? count($allh1match['0']) : count($allbmatch['0']);
$co
for($i=0;$i<$count;$i++)
{
@$
@$k
@
@$ke
@$
@
}
?>
<tr>
<td>
<?php
if($i==0){
?>
<a href="<?php echo $urlarray[$i];?>" style="color:blue"><?php echo $urlarray[$i];?></a>
<?php
}
else{
?>
<a href="<?php echo $urlarray[$i];?>"><?php echo $urlarray[$i];?></a>
<?php
}
?>
</td>
<td>
<?php echo getpagerank($urlarray[$i])
</td>
<td>
<?php echo $keywords_counth1; // TOTAL NUMBERS OF KEYWORDS MATCHED BETWEN H1 TAGS !
?>
</td>
<td>
<?php ceil(($keywords_counth1/$w
?>
</td>
<td>
<?php echo $keywords_countb; // TOTAL NUMBERS OF KEYWORDS MATCHED BETWEN B TAGS !
?>
</td>
<td>
<?php ceil(($keywords_countb/$wo
?>
</td>
<td>
<?php echo $keywords_countbody; // TOTAL NUMBERS OF KEYWORDS MATCHED BETWEN BODY TAG !
?>
</td>
<td>
<?php ceil(($keywords_countbody/
?>
</td>
</tr>
<?php } ?>
</table>
</fieldset>
<?php
}
else if(isset($_REQUEST['Submit
{
echo 'Please Enter a URL.';
}
?>
</body>
<!--<?php include('includes/footer.p
</html>
Roonaan - Thanks very much for the response and the detailed comments. I don't think, though, that it is working quite right. For example if I put
elder+law in the "Keyword" text box and then put "http://www.grosskopfandbl
Can you please take a quick look at your code again and see if you can see what the issue is:
example: http://70.87.107.194/~g3cr
thanks very much.
Hey. Thanks again. I am still seeing an issue though. for example
http://70.87.107.194/~g3cr
if you view the source of "www.sewing.org" there is an instance if "invisible thread" in the code.
<b>6.141 Invisible Thread</b>
Is there a reason why your code might be missing it?
by the way, in my example, if you enter "invisible thread" in the Keyword field it won't work, you have to enter a + sign between words in a phrase. In this case "invisible+thread".
Thanks for helping me with this.
The + is only required for the google page rank. But when you enter it, it will break the search, as the string "invisible+thread" is not anywhere in the , <h1> or <body>
For google page rank, you can solve that by using (around line 120):
replace
$url = 'http://www.google.com/sea
with
$url = 'http://www.google.com/sea
Then you can enter invisible thread without the + sign:
http://70.87.107.194/~g3cr
On that search I get a 1 on the keyword in bolds section.
Unfortunately that did not work. please see http://70.87.107.194/~g3cr
I am going to close this out and open an new question. I think that this is a different issue....
If you could respond to that, I would appreciate it.
Thanks very much!
Business Accounts
Answer for Membership
by: RoonaanPosted on 2009-01-12 at 22:53:03ID: 23360489
Hi,
;?>
;?> y[$i]);
.*)<\/body>) (.*)/ims', '\2', $page_contents);
)</h1>#ims', $page_contents, $m)) { $all_h1_words_string); \W)'.preg_ quote($key word).'(\W |$)/i', $all_h1_words_string, $m)); == 0) { * $num_keyword_in_h1);
</b>#ims', $page_contents, $m)) { $all_bold_words_string); \W)'.preg_ quote($key word).'(\W |$)/i', $all_bold_words_string, $m)); ue : $value_if_expression_is_fa lse y) == 0 ? 0 : (100 / count($all_bold_words_arra y) * $num_keyword_in_bold);
\W)'.preg_ quote($key word).'(\W |$)/i', strip_tags($body_content), $m)); ']+/', strip_tags($body_content)) );
);?> y));?>
Try and change:
<td>
<?php echo getpagerank($urlarray[$i])
</td>
<td>
h1 # result
</td>
<td>
h1 % result
</td>
<td>
b # result
</td>
<td>
b % result
</td>
<td>
body # result
</td>
<td>
body % result
</td>
</tr>
Into the following:
<td>
<?php echo getpagerank($urlarray[$i])
</td>
<?php
# 1 Get the html for the page
$page_contents = file_get_contents($urlarra
# 2 Distill the <body> section from the page content
$body_content = preg_replace('/^(.*)(<body(
# 3 Store the keyword in a local variable
$keyword = $_REQUEST['keyword'];
# 4 Test the h1's for keywords
$all_h1_words_string = '';
$all_h1_words_array = array();
# 4.1 Find all h1 tags, store all separate words in an array as well as a string
if(preg_match_all('#<h1>(.*?
$all_h1_words_string = strip_tags(implode('.', $m[1]));
$all_h1_words_array = preg_split('/[^\w\-\']+/',
}
# 4.2 Count the number of times the keyword is in the string with all h1 contents
$num_keyword_in_h1 = count(preg_match_all('/(^|
# 4.3 Compare the counted number with the amount of words, taking into account that a division by zero error should be prevented
if($num_keyword_in_h1 == 0 || count($all_h1_words_array)
$prc_keyword_in_h1 = 0;
} else {
$prc_keyword_in_h1 = (100 / count($all_h1_words_array)
}
# 5. Test the <b>'s for keywords. (Similar to h1)
$all_bold_words_string = '';
$all_bold_words_array = array();
# 5.1
if(preg_match_all('#<b>(.*?)
$all_bold_words_string = implode('.', $m[1]);
$all_bold_words_array = preg_split('/[^\w\-\']+/',
}
# 5.2
$num_keyword_in_bold = count(preg_match_all('/(^|
# 5.3 (same as 4.3 but in ternairy expression: $value = $somebooleanexpression ? $value_if_expression_is_tr
$prc_keyword_in_bold = $num_keyword_in_bold == 0 || count($all_bold_words_arra
# 6. Test the body. We don't use a array for storing all words, as that might get memory intensive
$num_keyword_in_body = count(preg_match_all('/(^|
$num_words_in_body = count(preg_split('/[^\w\-\
$prc_keyword_in_body = $num_keyword_in_body == 0 || $num_words_in_body == 0 ? 0 : (100 / $num_words_in_body * $num_keyword_in_body);
# 7. Output: For the count, I used number_of_matches / number_of_words instead of only number_of_matches. This allows for better debugging for the time being
?>
<td>
<?php printf('%d / %d', $num_keyword_in_h1, count($all_h1_words_array)
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_h1);?>
</td>
<td>
<?php printf('%d / %d', $num_keyword_in_bold, count($all_bold_words_arra
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_bold);?>
</td>
<td>
<?php printf('%d / %d', $num_keyword_in_body, $num_words_in_body);?>
</td>
<td>
<?php printf('%0.2f', $prc_keyword_in_body);?>
</td>
</tr>
Note that the code does not take into account any script tags, flash content or otherwise possibly relevant or most likely irrelevant html.