1
$value
= htmlentities(
$this
->value , ENT_QUOTES ,
'UTF-8'
);
$value
= htmlentities(
$this
->value , ENT_QUOTES ,
'UTF-8'
);
<?php
$authors = 'Chris & Sean';
if (strpos($authors, 'Chris')) {
echo 'Chris is an author.';
} else {
echo 'Chris is not an author.';
}
?>
<?php $a = 42; $b = 0; if( $a && $b ) { echo "TEST1 : Both a and b are true<br/>"; }else{ echo "TEST1 : Either a or b is false<br/>"; } if( $a and $b ) { echo "TEST2 : Both a and b are true<br/>"; }else{ echo "TEST2 : Either a or b is false<br/>"; } if( $a || $b ) { echo "TEST3 : Either a or b is true<br/>"; }else{ echo "TEST3 : Both a and b are false<br/>"; } if( $a or $b ) { echo "TEST4 : Either a or b is true<br/>"; }else { echo "TEST4 : Both a and b are false<br/>"; } $a = 10; $b = 20; if( $a ) { echo "TEST5 : a is true <br/>"; }else { echo "TEST5 : a is false<br/>"; } if( $b ) { echo "TEST6 : b is true <br/>"; }else { echo "TEST6 : b is false<br/>"; } if( !$a ) { echo "TEST7 : a is true <br/>"; }else { echo "TEST7 : a is false<br/>"; } if( !$b ) { echo "TEST8 : b is true <br/>"; }else { echo "TEST8 : b is false<br/>"; } ?>
This will produce the following result −
$rows=5; // number of row
for($i=1;$i<=$rows;$i++)
{
for($j=1;$j<=$i;$j++)
{
echo "*";
}
echo "<br />";
}
<?php
$rows=5; // number of row for($i=$rows;$i>=1;--$i) { for($j=1;$j<=$i;++$j) { echo $j; } echo "<br />"; } ?>
$rows=5; // number of row enter.
for($i=$rows;$i>=1;--$i)
{
for($space=0;$space<$rows-$i;++$space)
echo " ";
for($j=$i;$j<=2*$i-1;++$j)
echo "* ";
for($j=0;$j<$i-1;++$j)
echo "* ";
echo "<br />";
}
<?php
$year=2017; if($year%4==0) { $leap="It is a leap year"; } else { $leap="It is not a leap year"; } ?>
<?php
$fibo=array(0,1);
$num=4;for($i=2;$i<=$num-1;$i++){$fibo[$i]=$fibo[$i-1]+$fibo[$i-2];}?>
$check=0;
$num=$_POST['number'];
for($i=2;$i<=($num/2);$i++)
{
if($num%$i==0)
{
$check++;
if($check==1)
{
break;
}
}
}
window.onbeforeunload = function () { alert("Do you really want to close?"); };
<script> function checkInternetCon() { var status = navigator.onLine; if (status) { alert("Yes!! Working"); } else { alert("Sad!! Not Working "); } }</script>
Call above function on button onclick event.
<button onclick="checkInternetCon()">Check Internet Connection</button>
You can also use setInterval method in javascript
setInterval(function(){
var status = navigator.onLine;
if (status) {
console.log('Working..');
} else {
console.log('Not Working..');
}
}, 5000);
Learn more about php GD Library http://php.net/manual/en/book.image.php
create index.php file.
<?php # Note: Install GD libraries $filename = 'image.jpg'; //orignal file $newFilename = 'newImage.png'; // New file after modification list($current_width, $current_height) = getimagesize($filename); $left = 0; //crop left margin $top = 0;//crop right margin $cropWidth = 1056; $cropHeight = 400; $canvas = imagecreatetruecolor($cropWidth, $cropHeight); $currentImage = imagecreatefromjpeg($filename); imagecopy($canvas, $currentImage, 0, 0, $left, $top, $currentWidth, $currentHeight); imagejpeg($canvas, $newFilename, 100); ?>
CREATE TABLE IF NOT EXISTS `posts` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `title` VARCHAR(200) NOT NULL, `description` text NOT NULL, `created` datetime NOT NULL, `updated` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
create show.php file.
<?php $hostname = 'localhost'; // your mysql hostname $username = 'root'; // Your mysql db username $password = 'root'; // You mysql db password $database = 'demo'; // mysql db name $con = mysqli_connect($hostname, $username, $password, $database); if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $recordsPerPage=20; $start = ($page-1) * $recordsPerPage; $query = "SELECT * FROM posts LIMIT $start, $recordsPerPage"; $result = mysqli_query($con, $query); echo "<table><tr><th>Title</th><th>Description</th></tr>"; while ($row = mysqli_fetch_assoc($result)) { echo "<tr> <td>".$row['title']."</td><td>".$row['description']."</td></tr>"; } echo "</table>"; $query = "SELECT * FROM posts"; $result = mysqli_query($con, $query); //run the query $totalRecords = mysqli_num_rows($result); //count number of records $totalPages = ceil($totalRecords / $recordsPerPage); echo "<a href='show.php?page=1'>".'|<'."</a> "; // Go to 1st page for ($num=1; $num<=$totalPages; $num++) { echo "<a href='show.php?page=".$num."'>".$num."</a> "; }; echo "<a href='show.php?page=$totalPages'>".'>|'."</a> "; // Go to last page ?>
index.php
<?php error_reporting(0); // call parser library include('lib/simple_html_dom.php'); $html = file_get_html('http://webdeskers.com'); $posts = array(); foreach($html->find('tr') as $e) { $data = array(); foreach($e->find('td') as $d) { $data[] = $d->innertext; } array_push($posts, $data); } echo "<pre>"; print_r($posts); ?>