run php code online

Ads
 

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();

Ads









Related Tutorials/Questions & Answers:
PHP find online users
PHP find online users  How to find the online users in PHP
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
Advertisements
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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.
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
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
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
sql php code
sql php code       SQL PHP code executes the statement using the mysql_query ( ) function... and elaborate the example we have a PHP server scripting code that includes host, user

Ads