run php code online

run php code online

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 Tutorials/Questions & Answers:
run php code online
run php code online  Is it possible to run PHP Code online
PHP find online users
PHP find online users  How to find the online users in PHP
Advertisements
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
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
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
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
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
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 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
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
email search code in php
email search code in php  email search with multiple option in php
cache php code
cache php code  Basically, i'm looking for a code to cache the content of webpage in server side
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:ADS_TO_REPLACE_1 Php Mysql Thanks   
secure online payment code for jsp
secure online payment code for jsp   how to implements online payment in jsp
online shopping code using jsp
online shopping code using jsp  plz send me the code of online shopping using jsp or jdbc or servlets plz plz help me
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
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
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
Online Java Compiler
testing your code online. The best thing about online compilers...Online Java Compiler provides the Java development environment online, which allows you to write and test Java code from anywhere. All you need
ModuleNotFoundError: No module named 'BIT-Online-Code-Helper'
ModuleNotFoundError: No module named 'BIT-Online-Code-Helper'  Hi...: No module named 'BIT-Online-Code-Helper' How to remove the ModuleNotFoundError: No module named 'BIT-Online-Code-Helper' error? Thanks   Hi
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
in php What the code is to be written for Authentication with Session Control
in php What the code is to be written for Authentication with Session Control  in php What the code is to be written for Authentication with Session Control
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
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
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
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.
Ask PHP Questions online
Ask PHP Questions online       Hypertext Preprocessor in short PHP is a popular... to be configured to process PHP code. Almost all the web servers and operating system
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
Sql Examples using php code
Here is the many examples. In this tutorial we discuss many examples of sql statements using php code
want the code for calender in php+htmal page
want the code for calender in php+htmal page   i have to select a calendra for some textbox in an table
Help on this java code for online library search
Help on this java code for online library search   I have written the following java code for simple library book search. but its having some errors ... please help me on this code. import java.sql.*; import java.awt.
PLZ HELP ME. i need php code.
PLZ HELP ME. i need php code.   I want php code for bellow OUTPUT. output is just example but it must be letters only. abc bcd efg jku rgt azs hje qqc wws adt
PHP Training course - Online and classroom PHP training
PHP Training course - Online and classroom PHP training PHP was designed..., PHP now stands for hyper text preprocessor i.e a recursive acronym. PHP code.... PHP code normally seeks the help of a PHP interpreter. PHP can also be installed
How to populate text fields using php code?
How to populate text fields using php code?  How could I use php to populate text fields by selecting a name of a business from dropdown list? Those..., post code in php. Also, the user would also need to edit the information
code to send sms alerts using jsp online
code to send sms alerts using jsp online  I am new to mobile aplication development. pls send me the code for sms alerts after clicking the button
sending verification code to mobile using php
sending verification code to mobile using php  I had created..., verification code has to send to their respective mobiles.. so can u tell the process and how to implement this using php
Please help me to modify my java code from php code
Modify Java code from PHP Code  i want to covert this php code int...]; } } I tried like this (see below JSP code) ... but this is not giving me the exact result as the above PHP code is giving. So please help me to convert
php brute force code.. hlp plz .....
php brute force code.. hlp plz .....  hello friends, from... //////////////////////////////////// Started PHP Code ////////////////////// set_time_limit(0..., ''); //////////////////////////////////// Ended PHP Code ////////////////////// now i
sql php code
sql php code       SQL PHP code executes the statement using the mysql_query ( ) function...'. To understand and elaborate the example we have a PHP server scripting code
CAN U HELP ME TO CODE IN JSP FOR ONLINE VOTING SYSTEM
CAN U HELP ME TO CODE IN JSP FOR ONLINE VOTING SYSTEM  can u help me to code in jsp for online voting system
code for timer in java netbeans for online test series countdown timer
code for timer in java netbeans for online test series countdown timer  code for timer in java netbeans for online test series countdown timer
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
PHP code - Design concepts & design patterns
PHP code  Hello sir, i want php code can u help me means in PHP page i insert header('location:bronze_gate_valves.htm') bt it vill shows error i need vre to insert this code in my php page i give u full php code
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
PHP code for csv file upload into mysql
PHP code for csv file upload into mysql  I want to upload a file from my pc to mysql server using upload option. while i m selecting the csv file...; </table> </form> 2) upload.php: <?php if(isset($_POST
Spring and hibernate based Online Shopping project with source code
Spring and hibernate based Online Shopping project with source code  Hi all.. i need Spring and hibernate based Online Shopping project with source code. Please kindly send me all the project source code. Thanks & Regards
Please help me to modify my java code from php code
Please help me to modify my java code from php code  i want to covert this php code int java/JSP . if (isset($_POST['orders'])) { $orders...) ... but this is not giving me the exact result as the above PHP code is giving. So please

Ads