CONVERT JAVA TO PHP

CONVERT THIS CODE TO PHP TO GIVE A HOLLOW SQUARE

Page 1 of 1

4 Replies - 30027 Views - Last Post: 24 July 2010 - 05:31 AM Rate Topic: -----

#1 jay em   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-July 10

CONVERT JAVA TO PHP

Posted 23 July 2010 - 07:43 PM

i'M TRYING TO CONVERT THIS CODE TO PHP AND TO BE TRUE I DON'T KNOW ANYTHIN ABOUT HOW TO CONVERT IT
------------------------------------------------------------------------
Scanner in = new Scanner(System.in);
	        System.out.print("What size box would you like to create? ");
	        int size = in.nextInt();
	        for(int i = 0; i<size; i++)// Create a loop for every line of the box
	        {
	            if(i == 0)// if it is the first line we want to print size number of *
	                for(int h = 0; h<size; h++)
	                    if(h != size-1)// prints it all the way to the last one
	                        System.out.print("*");
	                    else System.out.println("*");// uses println for last to to start the next one off on a new line
	            else if(i==size-1)// If it is the very last row then it prints size number of * using the fo rloop below
	                for(int k = 0;k<size; k++)
	                    System.out.print("*");                 
	            else {// if it is neither first or last line it will print 1 sterisks spaces then asterisk
	                    for(int x = 0; x<size;x++)// keeps track of the column that it is in
	                        if(x == 0) // first column prints a * with print
	                            System.out.print("*");
	                        else if(x == size-1) // last one uses println for the last one to set it to a new line
	                            System.out.println("*");
	                        else System.out.print(" "); // if it is not the first column or the last will print spaces
	                }
	        }
	    }



Edited by macosxnerd101: Please, :code:.

Is This A Good Question/Topic? 0
  • +

Replies To: CONVERT JAVA TO PHP

#2 Crunch   User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: CONVERT JAVA TO PHP

Posted 23 July 2010 - 08:02 PM

For these code lines

Scanner in = new Scanner(System.in);
System.out.print("What size box would you like to create? ");
int size = in.nextInt();



You will need to echo "What size box would you like to create? "
next you will need to display a text-box where the user can input values
and once the user presses the submit button the value should be assigned to a variable.

The rest is very easy.
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12769
  • View blog
  • Posts: 45,954
  • Joined: 27-December 08

Re: CONVERT JAVA TO PHP

Posted 23 July 2010 - 08:20 PM

Unlike Java, PHP does not have a means of Console I/O like Scanner. PHP relies on HTML displays like forms to get input from the users. Take a look at forms, along with GET and POST to obtain the values from the user inputs. You can access them from the superglobals $_GET['component_name'] and $_POST['component_name'] repsectively.

Check out the PHP Tutorials section for more information.
Was This Post Helpful? 0
  • +
  • -

#4 mahcuz   User is offline

  • D.I.C Head
  • member icon

Reputation: 143
  • View blog
  • Posts: 213
  • Joined: 03-June 10

Re: CONVERT JAVA TO PHP

Posted 24 July 2010 - 03:42 AM

View Postmacosxnerd101, on 24 July 2010 - 02:20 AM, said:

Unlike Java, PHP does not have a means of Console I/O like Scanner. PHP relies on HTML displays like forms to get input from the users. Take a look at forms, along with GET and POST to obtain the values from the user inputs. You can access them from the superglobals $_GET['component_name'] and $_POST['component_name'] repsectively.

Check out the PHP Tutorials section for more information.


Actually, PHP has wrappers for this stuff. The php://stdin would be of interest here.

Mark.

P.S. PHP works just as well on the CLI as it does on the web. :D

This post has been edited by mahcuz: 24 July 2010 - 03:42 AM

Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12769
  • View blog
  • Posts: 45,954
  • Joined: 27-December 08

Re: CONVERT JAVA TO PHP

Posted 24 July 2010 - 05:31 AM

I didn't know that. Thanks for sharing! :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1