473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Array problems

Hello,

How I can realize that?
I have this code:

<?php
$url = "http://www.URL.com;
$content = file($url);
foreach($content as $line){
$pattern =
"/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/](\.(html|php|shtml|htm|xhtml|xml)))/i";

$count = 0;
if(preg_match_all($pattern,$line,$urls_back_array) ){
foreach($urls_back_array[0] as $url_back){
$count++;
echo $url_back;
}
}
}
?>

Now I want to make a loop - My script should count all links of all my *html
sites. But the script are not allowed to count double! Also the script shall
count all links on html sites correctly!
Example:
Home
|-Web
|-Forum
|--Site 1
|--Site 2
|--Site 3
|-Download
It should count 7 and list me all! =)

Gretting from Germany.
Jul 17 '05 #1
3 2023

"Sven Dzepina" <ma**@styleswitch.de> wrote in message
news:3f***********************@newsread4.arcor-online.net...
Hello,

How I can realize that?
I have this code:

<?php
$url = "http://www.URL.com;
$content = file($url);
foreach($content as $line){
$pattern =
"/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/](\.(html|php|shtml|htm|xhtml|xml)))/i";
$count = 0;
if(preg_match_all($pattern,$line,$urls_back_array) ){
foreach($urls_back_array[0] as $url_back){
$count++;
echo $url_back;
}
}
}
?>

Now I want to make a loop - My script should count all links of all my *html sites. But the script are not allowed to count double! Also the script shall count all links on html sites correctly!
Example:
Home
|-Web
|-Forum
|--Site 1
|--Site 2
|--Site 3
|-Download
It should count 7 and list me all! =)

Gretting from Germany.


I'm playing around here trying to do what you want to do... I'm not good
with my regular expressions using preg tools but I am using a mixture of
implode and explode to get at the url of each link (ie the "href=" bit in
the <A HREF" tag)... Once I have the website address that the link is
targeted at, I plan on using a mix of parse_url() and pathinfo() to identify
html type files. And in order to avoid duplices, the address will be
written in to an array which I will then run against array_unique.

Do these ideas help any?
Jul 17 '05 #2
Sven Dzepina wrote:
[...]
$count = 0;
if(preg_match_all($pattern,$line,$urls_back_array) ){
foreach($urls_back_array[0] as $url_back){
$count++;
echo $url_back;

[...]

I didn't check your regex.

I'd do it somewhat differently:

after preg_match_all() put the URLs into the index part of an array
### should this be __1__ ?
foreach ($urls_back_array[0] as $url_back) {
$large_url_array[$url_back]++;
## no echo
}
} ## if
} ## foreach

## echo now!
$total_count = 0;
$unique_urls = 0;
foreach ($large_url_array as $url=>$count) {
echo $url, ' : appears ', $count, ' times<br />';
$total_count += $count;
$unique_urls++;
}
echo '<br />Unique URLs: ', $unique_urls, '<br />';
echo '<br />Total links: ', $total_count, '<br />';


NOTE: This was typed directly in the editor and not tested.

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #3
Hello Rondell,

perhaps I've explained my aim imprecisely.
I want to count all Sites, which are linked on a homepage and list them.
My earlier solution was, that I have scanned all links and then I have
listed them all in a database.
But, it was a loop and so I fetched all links from the database to scann
them, too!
I didn't thought on this problem:
If I scann all links and insert them into a database, and I fetch them in
the same loop - Then I get always the same links.

Gretting.

"Randell D." <yo**************************@yahoo.com> schrieb im Newsbeitrag
news:NQ_ib.98843$6C4.43373@pd7tw1no...

"Sven Dzepina" <ma**@styleswitch.de> wrote in message
news:3f***********************@newsread4.arcor-online.net...
Hello,

How I can realize that?
I have this code:

<?php
$url = "http://www.URL.com;
$content = file($url);
foreach($content as $line){
$pattern =

"/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/](\.(html|php|shtml|htm|xhtml|xml)))/i";

$count = 0;
if(preg_match_all($pattern,$line,$urls_back_array) ){
foreach($urls_back_array[0] as $url_back){
$count++;
echo $url_back;
}
}
}
?>

Now I want to make a loop - My script should count all links of all my

*html
sites. But the script are not allowed to count double! Also the script

shall
count all links on html sites correctly!
Example:
Home
|-Web
|-Forum
|--Site 1
|--Site 2
|--Site 3
|-Download
It should count 7 and list me all! =)

Gretting from Germany.


I'm playing around here trying to do what you want to do... I'm not good
with my regular expressions using preg tools but I am using a mixture of
implode and explode to get at the url of each link (ie the "href=" bit in
the <A HREF" tag)... Once I have the website address that the link is
targeted at, I plan on using a mix of parse_url() and pathinfo() to

identify html type files. And in order to avoid duplices, the address will be
written in to an array which I will then run against array_unique.

Do these ideas help any?

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: shailashri_sk | last post by:
Hi, int *p; p++; here p now increments itself with the size of integer. similarly, I wanted to know, how to declare an pointer to an array ( say array of integers) where in it we do a p++ it...
8
by: engaref | last post by:
Hello Every body, I am new with C programming.I have received the Problems from my advisor on Array but I did not find any Proper answer yet. If Possible,please make a solution for the Problems....
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
3
by: Faustino Dina | last post by:
Hi, The following code is from an article published in Informit.com at http://www.informit.com/guides/content.asp?g=dotnet&seqNum=142. The problem is the author says it is not a good idea to...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.