<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Search Web Page</TITLE>
<meta name="description" content="Search Web Page">
<meta name="keywords" content="Search Web Page,Search Webpage URLs,Search Page,search site page,search website page,php,CMS,javascript, dhtml, DHTML">
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left;background-color:#ddd}
h1 {font:bold 28px Verdana; color:black;text-align:center}
td {font:normal 13px Verdana;text-align:left;background-color:#ccc}
.textbox {position:absolute;top:50px;left:190px;width:772px;}
.info {position:absolute;top:0px;left:2px;width:150px;background-color:#bbb;border:1px solid blue;padding:5px}
.ts {background-color:#8aa;border:6px solid blue;padding:6px}
.pw {position:absolute;top:150px;left:185px;width:820px;text-align:center}
</style>
<script language="javascript">
function convert(){
w=document.formurl.search.value;
encodeURIComponent(w);
document.formurl.search.value=w;}
</script>
</head>
<body>
<center><h1>Search Web Page</h1></center>
<?php
error_reporting(E_ERROR);

$f=$_POST['page'];
$S=rawurldecode($_POST['search']);
if (!isset($f)){
echo '<div class="pw"><table class="ts"><tr><td style="text-align:center"><form id="formurl" name="formurl" method="post" action="search-web-page.php" onsubmit="convert()"><b>web page URL (must end in php, htm, or html)</b><BR><label for="URL">URL: </b><input type="text" name="page" size="66" maxlength="99" value=""></label><br><br><b>Search word/phrase (only exact word or phrase will be searched for)</b><BR><label for="Search">Search: </b><input type="text" name="search" size="66" maxlength="99" value=""></label><br><br><input type="submit" value="Submit URL"><br><br><input type="reset" value="Reset"></form></td></tr></table></div>';

}else{

if (substr($f,-4)<>".htm" && substr($f,-4)<>"html" && substr($f,-4)<>".php"){echo '<script language="javascript">alert("Enter URL with htm, html, or php extension.\n\nPress a key to submit another URL.");window.location="search-web-page.php"; </script>';}

$f=strip_tags($f);
$f = str_replace(" ", "%20", $f); $f=trim($f);

$t = file_get_contents($f);

echo "<div class='textbox'>";
echo '<table width="772" border="1">';

if (strlen($S)<3 || $S=="the" || $S=="The" || $S=="THE") {echo '<script language="javascript">alert("Enter longer search terms.");window.location="search-web-page.php"; </script>';

}else{

$S=stripslashes($S);
$R = str_ireplace("<", "&lt;", $S);
$R = str_ireplace(">", "&gt;", $R);
$t=stripslashes($t);
$t = str_ireplace($S, '<span style="background-color:lightblue;">'.$R.'</span>', $t, $count);
$z='<span style="background-color:lightblue;">'.$R.'</span>';
$x=htmlentities($z, ENT_QUOTES);
$t=htmlentities($t, ENT_QUOTES);
$t = str_ireplace($x, $z, $t);
$t = str_ireplace("\n", "<BR>", $t);

if ($count){
echo "<a target='_blank' a HREF='".$f."'>".$f."</a><BR>";
echo "<BR><b>There were ".$count." matches.</b><BR><BR>";
echo $t."<BR><I><span style='color:green;background-color:#ddd'>".$f."</span></I>";
echo "<br><br></td></tr></table>";

}else{

echo '<script language="javascript">alert("Term was not found on this site.");window.location="search-web-page.php";</script>';}

}}
?>

</div>

<div id='info' class='info'>Search for whatever that's typeable, but if you search for text that has html entities in it, the highlighted results will be without the entities. For example: &lt;/span&gt; will return these results: </span>. And "%20" will only find " " but not "%20". <BR><A HREF="javascript:history.go(-1)">GO BACK</A> </div>
</body>
</html> 

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.

<?php
	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

Variables

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;  

Loops

1. IF Family:

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

If

if(conditional-expression){    
//code    
} 

If-else

if(conditional-expression){  
//code if condition is true  
} else {  
//code if condition is false  
} 

Nested-If-else

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  
...    
    
default:     
 // 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  
} 

For-each:

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

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

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

Functions

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) {  
  //code
}

How to call a Function

function_name (parameters)