Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6353891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:29:20+00:00 2026-05-24T22:29:20+00:00

I wrote the following Java program to connect google.com, get its HTML source code

  • 0

I wrote the following Java program to connect google.com, get its HTML source code in return, print the entire source code on the screen and then count the no. of line breaks (<br>) in the code. It is working fine.

String QUERY = "http://www.google.com";

URL url = new URL(QUERY);

URLConnection connection = url.openConnection();

connection.setDoInput(true);

InputStream inStream = connection.getInputStream();

BufferedReader input = new BufferedReader(new InputStreamReader(inStream));

String line = "";

int count = 0;

while ((line = input.readLine()) != null)

   {

   System.out.println(line);

   if(line.contains("br"))

      {

      count++;

      System.out.println(count);

      }

   }

The problem is, i want to write a similar code in PHP.
I know that URL’s can be called using fopen, and read into a String type variable using fread.

I want to know how i can print it (maybe echo?). But more importantly, how can i search for a desired string in the source code, and not just count the no. of occurences, but also retrieve a string/set of characters after the specified search-string’s location.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:29:20+00:00Added an answer on May 24, 2026 at 10:29 pm

    It’s a little bit of strange request and you seem to be printing the numbers after you print each lone (and not at the end). Also you seem to be counting every line that contrains a br just once but this should get you started for php:

    <?php
    $count = 0;
    foreach(file("http://www.google.com") as $line) {
        echo $line, PHP_EOL;
        if(strpos('br', $line)) { 
            ++$count;
        echo $count, PHP_EOL;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
i wrote following code to create a linkbutton programmatically, but its showing like lable
I recently wrote a java program transforming a SVG document to HTML/ Canvas :
When I execute the following java program, sometimes I get an empty response ,
I wrote a very simple program in java to get used with the use
I wrote a java program injecting spring Mail following instructions here - Spring EMail
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
if wrote the following code and do not understand why the trace returns false:
I wrote the following program #include <iostream> template<typename C, typename Res, typename... Args> class
I installed Java 1.7.0 in the following folder C:\Program Files\Java . My operating system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.