$find = [
// Spezial
'&lt;?php','?<span style="color: red">&gt;</span>',
// Element
// Attribut
// Attribut Value
// CSS
$repl = [
// Spezial
'<span style="color: blue">&quot;</span>',
'<span style="color: red">&gt;</span>',
'<span style="color: orange">&lt;?php</span>','<span style="color: orange">?&gt;</span>',
// Element
'<span style="color: red">&lt;!doctype</span>','<span style="color: red">&lt;/!doctype</span>',
'<span style="color: red">&lt;a</span>','<span style="color: red">&lt;/a</span>',
'<span style="color: red">&lt;aside</span>','<span style="color: red">&lt;/aside</span>',
'<span style="color: red">&lt;br</span>',
'<span style="color: red">&lt;body</span>','<span style="color: red">&lt;/body</span>',
'<span style="color: red">&lt;button</span>','<span style="color: red">&lt;/button</span>',
'<span style="color: red">&lt;caption</span>','<span style="color: red">&lt;/caption</span>',
'<span style="color: red">&lt;div</span>','<span style="color: red">&lt;/div</span>',
'<span style="color: red">&lt;fieldset</span>','<span style="color: red">&lt;/fieldset</span>',
'<span style="color: red">&lt;footer</span>','<span style="color: red">&lt;/footer</span>',
'<span style="color: red">&lt;form</span>','<span style="color: red">&lt;/form</span>',
'<span style="color: red">&lt;h1</span>','<span style="color: red">&lt;/h1</span>',
'<span style="color: red">&lt;h2</span>','<span style="color: red">&lt;/h2</span>',
'<span style="color: red">&lt;h3</span>','<span style="color: red">&lt;/h3</span>',
'<span style="color: red">&lt;head</span>','<span style="color: red">&lt;/head</span>',
'<span style="color: red">&lt;header</span>','<span style="color: red">&lt;/header</span>',
'<span style="color: red">&lt;html</span>','<span style="color: red">&lt;/html</span>',
'<span style="color: red">&lt;img</span>',
'<span style="color: red">&lt;input</span>','<span style="color: red">&lt;/input</span>',
'<span style="color: red">&lt;label</span>','<span style="color: red">&lt;/label</span>',
'<span style="color: red">&lt;legend</span>','<span style="color: red">&lt;/legend</span>',
'<span style="color: red">&lt;li</span>','<span style="color: red">&lt;/li</span>',
'<span style="color: red">&lt;link</span>','<span style="color: red">&lt;/link</span>',
'<span style="color: red">&lt;meta</span>',
'<span style="color: red">&lt;mark</span>','<span style="color: red">&lt;/mark</span>',
'<span style="color: red">&lt;ol</span>','<span style="color: red">&lt;/ol</span>',
'<span style="color: red">&lt;p</span>','<span style="color: red">&lt;/p</span>',
'<span style="color: red">&lt;strong</span>','<span style="color: red">&lt;/strong</span>',
'<span style="color: red">&lt;style</span>','<span style="color: red">&lt;/style</span>',
'<span style="color: red">&lt;table</span>','<span style="color: red">&lt;/table</span>',
'<span style="color: red">&lt;td</span>','<span style="color: red">&lt;/td</span>',
'<span style="color: red">&lt;textarea</span>','<span style="color: red">&lt;/textarea</span>',
'<span style="color: red">&lt;th</span>','<span style="color: red">&lt;/th</span>',
'<span style="color: red">&lt;title</span>','<span style="color: red">&lt;/title</span>',
'<span style="color: red">&lt;tr</span>','<span style="color: red">&lt;/tr</span>',
'<span style="color: red">&lt;ul</span>','<span style="color: red">&lt;/ul</span>',
// Attribut
'<span style="color: blue">action=</span>',
'<span style="color: blue">class=</span>',
'<span style="color: blue">href=</span>',
'<span style="color: blue">href^=</span>',
'<span style="color: blue">id=</span>',
'<span style="color: blue">lang=</span>',
'<span style="color: blue">method=</span>',
'<span style="color: blue">max=</span>',
'<span style="color: blue">min=</span>',
'<span style="color: blue">name=</span>',
'<span style="color: blue">number=</span>',
'<span style="color: blue">placeholder=</span>',
'<span style="color: blue">rel=</span>',
'<span style="color: blue">title=</span>',
'<span style="color: blue">type=</span>',
'<span style="color: blue">value=</span>',
'<span style="color: blue">xmlns=</span>',
// Attribut Value
'<span style="color: green">number</span>',
'<span style="color: green">post</span>',
'<span style="color: green">Reset</span>',
'<span style="color: green">reset</span>',
'<span style="color: green">Submit</span>',
'<span style="color: green">submit</span>',
// CSS
'<span style="color: blue">border:</span>',
'<span style="color: blue">background:</span>',
'<span style="color: blue">height:</span>',
'<span style="color: blue">margin:</span>',
'<span style="color: blue">max-width:</span>',
'<span style="color: blue">padding:</span>',
'<span style="color: blue">position:</span>',
'<span style="color: blue">width:</span>'
$codcol = '
<button syle="color: red">Button</button>
<input name="input" value="tru">
echo str_replace ($find, $repl, $codcol);


PHP Online Compiler

Write, Run & Share PHP code online using OneCompiler's PHP online compiler for free. It's one of the robust, feature-rich online compilers for PHP language, running on the latest version 7. Getting started with the OneCompiler's PHP compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as PHP and start coding.

Taking inputs (stdin)

OneCompiler's PHP online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample PHP program which takes name as input and prints hello message with your name.

	fscanf(STDIN, "%s\n", $name);           
    echo "Hello ".$name.".\n";

About PHP

PHP(Hypertext Preprocessor) is widely used server sripting language by Rasmus Lerdorf in the year 1994.

Key features

  • Free
  • powerful tool for making dynamic and interactive web pages
  • can integrate with almost all popular databases like MySQL, PostgreSQL, Oracle, Sybase, Informix, Microsoft SQL Server etc.
  • C like Syntax and easy to learn.
  • Object oriented scripting language.
  • easily embeddable into HTML
  • Loosely typed language.

Syntax help


In PHP, there is no need to explicitly declare variables to reserve memory space. When you assign a value to a variable, declaration happens automatically. Variables are case-sensitive in PHP.

$variable_name = value;  


1. IF Family:

If, If-else, Nested-Ifs are used when you want to perform a certain set of operations based on conditional expressions.




//code if condition is true  
} else {  
//code if condition is false  


if(condition-expression1) {  
    //code if above condition is true  
} elseif(condition-expression2){  
    //code if above condition is true  
elseif(condition-expression3) {  
    //code if above condition is true  
else {  
    //code if all the conditions are false  

2. Switch:

Switch is used to execute one set of statement from multiple conditions.

switch(conditional-expression) {    
case value1:    
 // code if the above value is matched    
 break;  // optional  
case value2:    
 // code if the above value is matched    
 break;  // optional  
 // code to be executed when all the above cases are not matched;    

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  // code  


// you can use any of the below syntax
foreach ($array as $element-value) {  

foreach ($array as $key => $element-value) {   

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition) {  
 // code 

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {
  // code 
} while (condition); 


Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

How to define a Function

function function_name(parameters) {  

How to call a Function

function_name (parameters)