Home Answers Viewqa PHP run php code online

 
 


Java Coder
run php code online
1 Answer(s)      2 years and 7 months ago
Posted in : PHP

Is it possible to run PHP Code online?
View Answers

November 28, 2011 at 5:28 PM


class createProjectFiles { private $createMinParts; private $createMaxParts; private $uniqueCarsCount; private $manufacturers; private $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private $parts = array(); private $vehicles = array(); private $vehicleNumbers = array(); private $uniquePartNumbers = array(); private $uniqueCars = array(); private $partTransactions;

public function __construct()
{
    $this->createMinParts = 500;
    $this->createMaxParts = 5000;
    $this->uniqueCarsCount = 50;    
    $this->partTransactions = 10; 

    $this->manufacturers = array
    (
        'Toyota',
        'General Motors',
        'Volkswagen',
        'Hyundai',
        'Ford',
        'Nissan',
        'Honda',
        'PSA',
        'Suzuki',
        'Renault',
        'Fiat',
        'Darnier AG',
        'Chrysler',
        'BMW',
        'Mazda',
        'Mitsubishi',
        'Tata',
        'FAW',
        'Geely',
        'Cherry',
        'Fuji'
    );
}

public function setMinParts( $min )
{
    $this->createMinParts = $min;
}

public function setMaxParts( $max )
{
    $this->createMaxParts = $max;
}

public function setMaxCarCount( $count )
{
    $this->uniqueCarsCount = $count;
}

public function createPartTransactions( $partTransactions )
{
    $this->partTransactions = $partTransactions; 
}

public function generateFiles()
{
    $this->generateStock();
    $this->addSubstitutePartsToStock();
    $this->writeStockFile();
    $this->writeVehicleFile();

    sort( $this->uniquePartNumbers );
    sort( $this->uniqueCars );
    sort( $this->vehicleNumbers );
    sort( $this->vehicles );

    $this->writeTransFile();

}

private function generateVehicleNumber()
{
    if( $this->uniqueCarsCount > 0 )
    {
        // create random car
        $vehicleNumber = rand( 10000 , 99999 );
        $this->uniqueCars[] = $vehicleNumber;
        $this->uniqueCarsCount--;
        return sprintf( "%05s" , $vehicleNumber );
    }
    else
    {
        // pick random existing car
        $vehicleNumber = $this->uniqueCars[ rand( 0 , count( $this->uniqueCars ) -1 ) ];
        return sprintf( "%05s" , $vehicleNumber );
    }
}

private function generatePartNumber()
{
    $randomLetter1 = $this->chars[ rand( 0 , 25 ) ];
    $randomLetter2 = $this->chars[ rand( 0 , 25 ) ];
    $partNumber = rand( 1 , 99999 );

    return $randomLetter1 . $randomLetter2 . sprintf( "%05s" , $partNumber );
}


private function getExistingPartNumber()
{
    $randError = rand( 0 , 5 );

    if( $randError == 3 )
    {
        //bogus part
        return "AA00000";
    }
    else
    {
        return $this->uniquePartNumbers[ rand( 0 , count( $this->uniquePartNumbers ) - 1 ) ]; 
    }   
}

private function getExistingVehicleNumber()
{
    $randError = rand( 0 , 5 );

    if( $randError == 3 )
    {
        //bogus car
        return "00000";
    }
    else
    {
        $vehicleNumber = $this->uniqueCars[ rand( 0 , count( $this->uniqueCars ) -1 ) ];
        return sprintf( "%05s" , $vehicleNumber );
    }   
}

private function generateStock()
{
    for( $i = 0; $i < rand( $this->createMinParts , $this->createMaxParts ); $i++ )
    {
        $partNumber = $this->generatePartNumber();
        $vehicleNumber = $this->generateVehicleNumber();

        $description = "--------dont care--------";
        $quatity = rand( 0 , 99999 );
        $price = rand( 10 , 999999 );
        $reorderL = rand( 0 , 999 );
        $reorderQ = rand( 0 , 99999 );
        $numparts = rand( 0 , 10 );

        if( in_array( $partNumber , $this->uniquePartNumbers ) )
        {
            continue;
        }
        else
        {
            $part = array
            (
                "partNumber" => $partNumber,
                "vehicleNumber" => $vehicleNumber,
                "description" => $description,
                "quatity" => sprintf( "%05s" , $quatity ),
                "price" => sprintf( "%06s" , $price ),
                "reorderL" => sprintf( "%03s" , $reorderL ),
                "reorderQ" => sprintf( "%05s" , $reorderQ ),
                "numSubparts" => sprintf( "%02s" , $numparts ),
                "part1" => '',
                "part2" => '',
                "part3" => '',
                "part4" => '',
                "part5" => '',
                "part6" => '',
                "part7" => '',
                "part8" => '',
                "part9" => '',
                "part10" => ''
            );

            $this->parts[] = $part;

            if( !in_array( $vehicleNumber , $this->vehicleNumbers ) )
            {
                $this->vehicleNumbers[] = $vehicleNumber;
                $this->vehicles[ $vehicleNumber ] = array( $vehicleNumber , "-- vehicle description --" , 
                    sprintf( "%20s" , $this->manufacturers[ rand ( 0 , count( $this->manufacturers ) - 1 ) ] ) );
            }

            $this->uniquePartNumbers[] = $partNumber;
        }
    }
}

private function addSubstitutePartsToStock()
{
    // add substitute parts to the parts from the parts

    for( $t=0; $t < count( $this->parts ); $t++ )
    {
        $thepart = $this->parts[ $t ];
        $numofsubparts = $thepart[ 'numSubparts' ];

        $ignoreDuplicates = array();

        for( $y =0; $y < $numofsubparts; $y++ )
        {
            $rand = rand( 0 , count( $this->parts ) -1 );

            if( in_array( $this->parts[ $rand ][ 'partNumber' ], $ignoreDuplicates ) )
            {
                $y = $y -1;
                continue;
            }
            else
            {
                $index = "part" . ( $y + 1 );
                $this->parts[ $t ][ $index ] = $this->parts[ $rand ][ 'partNumber' ];
                $ignoreDuplicates[] = $this->parts[ $rand ][ "partNumber" ];
            }
        }
    }
}


private function writeStockFile()
{
    // bang out the stock master file

    $fp = fopen( "INAUTO-SMF.DAT" , 'w' );

    if( $fp )
    {
        foreach( $this->parts as $part )
        {
            fwrite( $fp , sprintf( "%-128s" , $part[ 'partNumber' ] . 
                    $part[ 'vehicleNumber' ] . 
                    $part[ 'description' ] . 
                    $part[ 'quatity' ] . 
                    $part[ 'price' ] . 
                    $part[ 'reorderL' ] . 
                    $part[ 'reorderQ' ] . 
                    $part[ 'numSubparts' ] . 
                    $part[ 'part1' ] . 
                    $part[ 'part2' ] . 
                    $part[ 'part3' ] . 
                    $part[ 'part4' ] . 
                    $part[ 'part5' ] . 
                    $part[ 'part6' ] . 
                    $part[ 'part7' ] . 
                    $part[ 'part8' ] . 
                    $part[ 'part9' ] . 
                    $part[ 'part10' ] ) . "\r\n" );
        }

        fclose( $fp );
    }
}


private function writeVehicleFile()
{
    $fp = fopen( "INAUTO-VEHICLE.DAT" , 'w' );

    if( $fp )
    {
        ksort( $this->vehicles );
        foreach( $this->vehicles as $vehicle )
        {
            fwrite( $fp , sprintf( "%-49s" , $vehicle[ 0 ] . $vehicle[ 1 ] . $vehicle[ 2 ] ) . "\r\n" );
        }
        fclose( $fp );
    }
}


private function writeTransFile()
{
    $fp = fopen( "INAUTO-TRANS.DAT" , 'w' );

    if( $fp )
    {
        $partNumberTransactions = $this->createOrderedPartNumberlist();

        for( $partTrans = 0; $partTrans < count( $partNumberTransactions ); $partTrans++ )
        {
            $i = 0;
            $records = array();
            $p = rand( 1 , 5 );

            while( $i < $p )
            {
                $type = rand( 1 , 5 );

                switch( $type )
                {
                    case 1:
                        $records[ "$type" ] = $this->createInsertion( $partNumberTransactions[ $partTrans ] );
                    break;
                    case 2:
                        $records[ "$type" ] = $this->createDeletion( $partNumberTransactions[ $partTrans ] );
                    break;
                    case 3:
                        $records[ "$type" ] = $this->createQuantity( $partNumberTransactions[ $partTrans ] );
                    break;
                    case 4:
                        $records[ "$type" ] = $this->createAddSub( $partNumberTransactions[ $partTrans ] );

                    break;
                    case 5:
                        $records[ "$type" ] = $this->createRemoveSub( $partNumberTransactions[ $partTrans ] );
                    break;
                }

                $i++;
            }

            ksort( $records );

            foreach( $records as $key => $val )
            {
                fwrite( $fp , sprintf( "%-129s" , $val ) . "\r\n" );
            }
        }
        fclose( $fp );
    }
}

private function createOrderedPartNumberlist()
{
    $list = array();

    for( $i = 0; $i < $this->partTransactions; $i++ )
    {
        if( $i % 5 > 0 )
        {
            // choose existing part number
            $list[] = $this->uniquePartNumbers[ rand( 0 , count( $this->uniquePartNumbers ) - 1 ) ]; 
        }
        else
        {
            $list[] = $this->generatePartNumber();
        }
    }

    sort( $list );

    return $list;
}

private function createDeletion( $part )
{
    return "2" . $part;
}

private function createQuantity( $part )
{
    return "3" . $part . sprintf( "%05s" , rand( 0 , 99999 ) );
}

private function createAddSub( $part )
{
    return "4" . $part . $this->getExistingPartNumber();
}

private function createRemoveSub( $part )
{
    return "5" . $part . $this->getExistingPartNumber();
}

private function createInsertion( $part )
{
    $partNumber = $part;
    $vehicleNumber = $this->generateVehicleNumber();

    $description = "--------dont care--------";
    $quatity = rand( 0 , 99999 );
    $price = rand( 10 , 999999 );
    $reorderL = rand( 0 , 999 );
    $reorderQ = rand( 0 , 99999 );
    $numparts = rand( 0 , 10 );

    $part = array
    (
        "partNumber" => $partNumber,
        "vehicleNumber" => $vehicleNumber,
        "description" => $description,
        "quatity" => sprintf( "%05s" , $quatity ),
        "price" => sprintf( "%06s" , $price ),
        "reorderL" => sprintf( "%03s" , $reorderL ),
        "reorderQ" => sprintf( "%05s" , $reorderQ ),
        "numSubparts" => sprintf( "%02s" , $numparts ),
        "part1" => '',
        "part2" => '',
        "part3" => '',
        "part4" => '',
        "part5" => '',
        "part6" => '',
        "part7" => '',
        "part8" => '',
        "part9" => '',
        "part10" => ''
    );

    $ignoreDuplicates = array();

    for( $y =0; $y < $numparts; $y++ )
    {
        $randSubPart = $this->getExistingPartNumber();

        if( in_array( $randSubPart , $ignoreDuplicates ) )
        {
            $y = $y -1;
            continue;
        }
        else
        {
            $index = "part" . ( $y + 1 );
            $part[ $index ] = $randSubPart;
            $ignoreDuplicates[] = $randSubPart;
        }
    }

    return  "1" . 
            $part[ 'partNumber' ] . 
            $part[ 'vehicleNumber' ] . 
            $part[ 'description' ] . 
            $part[ 'quatity' ] . 
            $part[ 'price' ] . 
            $part[ 'reorderL' ] . 
            $part[ 'reorderQ' ] . 
            $part[ 'numSubparts' ] . 
            $part[ 'part1' ] . 
            $part[ 'part2' ] . 
            $part[ 'part3' ] . 
            $part[ 'part4' ] . 
            $part[ 'part5' ] . 
            $part[ 'part6' ] . 
            $part[ 'part7' ] . 
            $part[ 'part8' ] . 
            $part[ 'part9' ] . 
            $part[ 'part10' ];
}

}

$creator = new createProjectFiles(); $creator->setMinParts( 500 ); // minimum amount of parts $creator->setMaxParts( 5000 ); // maximum amount of parts $creator->setMaxCarCount( 50 ); // after X cars, no new one will be gnerated and the old car numbers reused $creator->createPartTransactions( 120 ); // number of parts, may contain up to 3 transations per part $creator->generateFiles();









Related Pages:
run php code online
run php code online  Is it possible to run PHP Code online
PHP Auto schedule and run php scripts
PHP Auto schedule and run php scripts  Hi... This is vinay.. I am trying to schedule the execution of php scripts and run them... But I dont want... that php which automatically runs the scheduled work.. But I am not getting how
Failed to run Online Quiz Application in JSP - JSP-Interview Questions
Failed to run Online Quiz Application in JSP   Hi, I have been following your following link to run the online quiz application, but I failed... your question. Thanks  Hi, I cannot run your online quiz
PHP find online users
PHP find online users  How to find the online users in PHP
Run a simple EJB code
Run a simple EJB code  I found the code this. However, as I have no idea with EJB, I can't understand how to run it. Can anybody help me by giving steps (by giving snapshots or writing full procedure)how to run it (any platform
Run a simple EJB code
Run a simple EJB code  I found the code this. However, as I have no idea with EJB, I can't understand how to run it. Can anybody help me by giving steps (by giving snapshots or writing full procedure)how to run it (any platform
Online Shopping Portal for xyz.com
Online Shopping Portal for xyz.com  XYZ.com wants to create an online shopping portal for managing its registered customers and their shopping... to realize their dream of having an online shopping portal? Steps to be followed 1
online shoopping portal
online shoopping portal  XYZ.com wants to create an online shopping... their dream of having an online shopping portal? Steps to be followed Create.... Implement the functionality using the server side scripting language, PHP
Online Shopping Portal for xyz.com
Online Shopping Portal for xyz.com  XYZ.com wants to create an online shopping portal for managing its registered customers and their shopping... to realize their dream of having an online shopping portal? Steps to be followed 1
Online Shopping Portal
Online Shopping Portal  XYZ.com wants to create an online shopping... their dream of having an online shopping portal? Steps to be followed Create.... Implement the functionality using the server side scripting language, PHP. Integrate
Ask PHP Questions online
Ask PHP Questions online       Hypertext Preprocessor in short PHP is a popular... to process PHP code. Almost all the web servers and operating system supports PHP
ONLINE EXAM CODE SPLIT
ONLINE EXAM CODE SPLIT  hi.. im developing online exam for c programming in jsp.. i read the question from database as a string suppose String ques="#include<stdio.h>main(){int i;for(i=0;<100;i++){printf("hai
PHP Training online in India
PHP Training online in India We are providing PHP Training online in India using desktop sharing softwares. PHP Training online is very effective way to learn PHP from our experts. You can take the PHP Training online from your home
secure online payment code for jsp
secure online payment code for jsp   how to implements online payment in jsp
calendar in php code - PHP
calendar in php code   Any Idea to create a calendar for school in PHP? I need a simple nd handy code
online voting
online voting  can i have the code for online voting in java
online voting
online voting  can i have the code for online voting in java
Pagination in PHP code - PHP
Pagination in PHP code  3.Pagination in PHP codeIs it possible to get the paging in PHP without database call? How will I show the image instead of numbering? any code that can help
PHP PHP Triad Tutorial
\HTDOCS folder type the following code and save it as Hello.php. <?php echo... PHP-Triad Tutorial      ... on the PHPTriad server. PHPTriad is a software package which installs PHP
PHP Introduction
file that are saved into .php extension. It is very easily write and test PHP code. Any editor like notepad can be used to write and save the code. To run the PHP... file. So, you can make your html dynamic by using the PHP code in it. Generally
It?s Easy to See Why You Should Learn PHP
that the code will run properly when it is put online. Of course, PHP will be very...The code of a website is important. It is used to get the site to run properly.... PHP is one such type of coding system that can be used. It can be very useful
Run this code..plzz - Java Beginners
Run this code..plzz  Hi Friend... ERROR: Exception in thread "main...;Hi friend, I am sending code according to your requirement but you are defined in this example what you want to do please explain and send me full code
PHP
as console applications. You can write PHP applications and run it as cron job on Linux, Unix, Solaris and Mac servers. PHP code is embedded into HTML pages... You can embedded PHP code into your html file and save it as .php or .php3
How to run PHP Script from the command line ?
How to run PHP Script from the command line ?  Running PHP Script from the command line   Actually it is very simple to run php script... expect. You can also check : http://www.phpzag.com/running-php-script-from
online shopping
online shopping   Hai sir/madam, i'm working on online shopping project.requirements is oracle10g,servlets/jsp... what... to save.industry which one prefers storing or saving.explain and give the source code
php
php  what is php   PHP is one of the most used open source server-side scripting language, which runs on almost all the platform. PHP is cross-platform and it run on many platform including Windows, Linux, Mac OS
online examination
online examination  Hi, i am doing online examination project, i have some problem with get a paper form database and count the right answer... ,please send this code in my email id-"prakash.pantnagar@gmail.com" as soon
Eval () PHP Function, Example of Eval () PHP Function
in MySQL table or in text file and then run the same in a PHP script. The PHP... as PHP code. The string parameter must be a valid PHP code and end with a semicolon, just like regular PHP code. After the evaluation of the string
Java code to run unix command - Java Beginners
Java code to run unix command  Hi, I need a java code to connect to a remote unix server and run a unix command. Please help. Regards, Pratyush
online exam
online exam  The file geneexpr500x204.gct contains gene expression values for 500 genes (analytes) and 204 samples. (a) Extract the sample names... source code and the output files. Use - any of shell script or perl. This file
php
php  plz tell me code for PHP SQL Insert,delete,update,view is used to insert the record from HTML page to Mysql database using in single PHP form
to run html code in web browser - JSP-Servlet
to run html code in web browser  how to run jsp file which calls html file on web browser??  Hi Friend, Try the following code: 1)form.jsp: Enter Name: 2)welcome.html: Add Profile Edit
online voting system source code in java
online voting system source code in java  Please send me source code for online voting system in java. please replay as fast as. Thank you
online shopping project report with source code in java
online shopping project report with source code in java  Dear Sir/Mam, i want to a project in java with source code and report project name online shopping. thank you
php download file code
php download file code  PHP code to download the files from the remote server
user authentication code in php - PHP
user authentication code in php  Hi, Can you please send me a user authentication code in php? or just post the guidelines to authenticate a user. Thanks
online examination
online examination  coding for multiple choice question in jsp  ...(ques,op1,op2,op3,op4,ans) and answers(id,ans). Then try the following code: 1)form.jsp...: http://www.roseindia.net/jsp/online-quiz-application-jsp.shtml
email search code in php
email search code in php  email search with multiple option in php
php login and logout code
php login and logout code  Hi, Can anyone share there code for creating a user login and logout page in PHP?or any useful tutorial that can help to create a login and logout application in PHP.. Thanks in Advance
Java Certification Training Online
Java Certification Training Online So, why should we go for a online... a code for executing an application. This language has a great significance... India's online java certification training program is meant for people who
Applet run with appletviewer but not in browser, any code problem.
Applet run with appletviewer but not in browser, any code problem.  ... fine but not run from the browser as http://localhost:8080/ProgressoApplication... the 52 cards will be show in browser as by "appletviewer" and run as "java applet" I
What is a PHP File?
A PHP file includes PHP code, functions, text HTML tags and scripts that can process online forms, get the date and time, or access information from a database, such as MySQL database. A PHP file returns to the browser as a plain HTML
cache php code
cache php code  Basically, i'm looking for a code to cache the content of webpage in server side
PHP
, Linux, Mac Os, Sun Solaris and others. But for processing the PHP code... the origination of Zend Engine – the catalyst of PHP code processor... PHP Services PHP refers to Hypertext Preprocessor, a general
java code to insert select at run time....????
java code to insert select at run time....????  java database code to retrieve data at runtime and please give codes for insert delete too.... using jsp and withot jsp   1)application.jsp: <%@ page import="java.sql.
Mysql-Php code
Mysql-Php code  I want to mysql script for query data from two tables in the mysql database trough php code. Can you help me   Hi Friend, Please visit the following link: Php Mysql Thanks   Hi Friend
Run time error - WebSevices
Run time error  Hello, Anyone know, how run the template files in zend framework.Anybody help me. Rgds, Pras  code to help in solving the problem : protected function _run($template
php
how can i write a code to book a space in hotel  how can i write a code to book a space in hotel
online shopping project
online shopping project  sir, plz can u send me the coding of simple application of online shopping cart project using jsp and servlets which should be run in netbeans without any errors
can i know the error in this code... am unable to run this code
can i know the error in this code... am unable to run this code  ... code like < >. The for is improper and not completed. Moreover, you have open and close braces properly. Anyways, we have modified your code. Here

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.