strpos in php: PHP strpos(), substr(),

Find the first position for the string inside the string :- strpos() echo strpos(“I love apple, I love apple too!”,”apple”);   Return word from the string substr() substr(“Hello world”,6); echo substr(“Hello world”,0,-1)   – Result : Hello worl echo substr(“Hello world”,-10,-2) – Result : ello wor echo substr(“Hello world”,0,-6) – Result : Hello  

Read More

Essential PHP Interview Questions & Answer

php-interview-questions

1) Whats is CURL ? A command line tools for sending and getting files and response. 2) How to use CURL in PHP ? // Step 1 $cSession = curl_init(); // Step 2 curl_setopt($cSession,CURLOPT_URL,”http://www.yahoo.com/search?q=curl”); curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true); curl_setopt($cSession,CURLOPT_HEADER, false); //Step 3 $result=curl_exec($cSession); //Step4 curl_close($cSession); //Step5 echo $result; 3) How to access authenticated WEBSITE Datas in CURL ? // http header: “Authorization: Basic “. base64_encode(“username:password”); // Set the below option for CURL curl_setopt($ch, CURLOPT_USERPWD, ‘username:password’); 4) What is Buffer ? Store all output results into a buffer for improving network performance. Access the…

Read More

PHP | mail | Send email thru PHP mail function.

Send mail thru PHP Mail function Mail Function send an email from the direct PHP Script. Syntax : mail(to,subject,message,headers,parameters); Example : $to = “text1@gmail.com”; $subject = “HTML email”; $message = “<html><head><title>HTML email</title></head> <body> <p>This email contains HTML Tags!</p> <table> <tr><th>Firstname</th><th>Lastname</th></tr> <tr><td>John</td><td>Doe</td></tr> </table></body></html>”; $headers = “MIME-Version: 1.0” . “\r\n”; $headers .= “Content-type:text/html;charset=UTF-8” . “\r\n”; $headers .= ‘From: <text@gmail.com>’ . “\r\n”; mail($to,$subject,$message,$headers);

Read More

PHP – PDF Generator

FPDF – PDF Generation FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. http://www.fpdf.org/ fPDF Tutorial – Sample Code :- require(‘fpdf/fpdf.php’); $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont(‘Arial’,’B’,16); $pdf->Cell(40,10,’Hello World!’); $pdf->Output();

Read More