php include pages or files

php include page example

php include pages or files The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website. It is possible to insert … Read more

how to get date of yesterday using php

php how to example

how to get date of yesterday using php   <?php $test=date(‘d.m.Y’,strtotime(“-1 days”)); echo $test; ?> or <?php $test=date(‘d-m-Y’,strtotime(“-1 days”)); echo $test; ?> or <?php $test=date(‘y-m-d’,strtotime(“-1 days”)); echo $test; ?>

PHP readfile() Function – file handling

php how to example

PHP readfile() Function – file handling The readfile() function reads a file and writes it to the output buffer. Assume we have a text file called “blog.eduguru.txt”, stored on the server, that looks like this: “Hi, This is a test file. This is created to show the example of readfile function in php.” The PHP code to … Read more

PHP print Statement

php_print_statement

PHP print Statement The print statement can be used with or without parentheses: print or print(). Display Text The following example shows how to output text with the print command (notice that the text can contain HTML markup): Example <?php print “<h2>PHP is Fun!</h2>”; print “Hello world!<br>”; print “I’m about to learn PHP!”; ?> Output: PHP is Fun! Hello world! I’m about to learn PHP! … Read more

PHP substr() function

php substr function

<?php   // PHP program to illustrate substr() function Substring($str){     $len = strlen($str);     echo substr($str, 8), “\n”;     echo substr($str, 5, $len), “\n”;     echo substr($str, -5, 10), “\n”;     echo substr($str,-8, -5), “\n”; }   // Driver Code $str=”blogsforblogs”; Substring($str);   ?> Output: blogs forblogs blogs for The substr() is a built-in function in PHP that is … Read more

How to identify server IP address in PHP

php how to example

How to identify server IP address in PHP   or the server ip: $_SERVER[‘SERVER_ADDR’]; and this for the port $_SERVER[‘SERVER_PORT’]; You can use this in CRUL as below: <?php // create a new cURL resource $ch = curl_init (); // set URL and other appropriate options curl_setopt ($ch, CURLOPT_URL, “http://blog.eduguru.in/test”); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt … Read more

Saving a curl response into a php variable

php-mysql

Saving a curl response into a php variable Here is example to save a curl resonse into a variable in php <?php //URL of targeted site $url = “http://www.putyourapihere.com/”; $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // grab URL and pass it to … Read more

get the last 7 characters of a PHP string

php-mysql

get the last 7 characters of a PHP string Use substr() with a negative number for the 2nd argument. $newstring = substr($dynamicstring, -7); string substr ( string $string , int $start [, int $length ] ) If start is negative, the returned string will start at the start’th character from the end of string Example: <?php echo … Read more

refresh an iframe in php page

php left trim function

refresh an iframe in php page   <script type=”text/javascript”> var timer; function refreshIframe(){ if(timer) clearInterval(timer) timer = setTimeout(refreshIframe,5000) var iframe = document.getElementById(‘iframe’); iframe.src=’http://blog.eduguru.in’; } refreshIframe(); </script> <iframe id=”iframe” src=”http://blog.eduguru.in” width=”100%” height=”300″> <p>Your browser does not support iframes.</p> </iframe>    

Curl in html forms : Use of curl

curl

Curl in html forms : Use of curl Forms are the general way for the user to enter data in, and then press some kind of ‘OK’ or ‘Submit’ button to get that data sent to the server. The server then typically uses the posted data to decide how to act. Like using the entered … Read more