Wednesday, 30 September 2015

count_chars - Count Number of character of string with PHP

count_chars - Count Number of character of string with PHP

mixed count_chars ( string $string [, int $mode = 0 ] )
Return information about characters used in a string
Mode value can have 0-5 and return following results
  1. 0 - Return an array with the byte-value as key and the frequency of every byte as value.
  2. 1 - same as 0 but only byte-values with a frequency greater than zero are listed.
  3. 2 - same as 0 but only byte-values with a frequency equal to zero are listed.
  4. 3 - a string containing all unique characters is returned.
  5. 4 - a string containing all not used characters is returned.



Counts the number of occurrences of every byte-value (0..255) in string and returns it in various ways.

<?php
$data 
"Two Ts and one F.";

foreach (
count_chars($data1) as $i => $val) {
   echo 
"There were $val instance(s) of \"" chr($i) , "\" in the string.\n";
}
?>


065 PHP من الألف إلى الياء Arabic التعامل مع النصوص Strings pt1

Friday, 25 September 2015

Codeigniter Interview Questions for Experienced




Question: What is CodeIgniter?
Codeigniter is an open source framework for web application on PHP. It is loosely based on MVC pattern and it is similar to CakePHP.


Question: What is Stable version of CodeIgniter?
Version: 3.0.4,
Date January 13, 2016


Question: In Which language CodeIgniter is written?
PHP

Question: What are the features of codeigniter? Open source framework
Light Weight
CodeIgniter is Extensible
Full Featured database classes


Question: How to access config variable in codeigniter?
$this->config->item('variable name');


Question: How to unset session in codeigniter?
 $this->session->unsetuserdata('somename');;


Question: How do you get last insert id in codeigniter?
 $this->db->insertid();;


Question: How to print SQL statement in codeigniter model??
 $this->db->lastquery();;


Question: What are hooks in CodeIgniter?
CodeIgniter's Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files.
    $hook['pre_controller'] = array(
            'class'    => 'MyClass',
            'function' => 'Myfunction',
            'filename' => 'Myclass.php',
            'filepath' => 'hooks',
            'params'   => array('param1', 'param2', 'param3')
   );



Question: How to load model in CodeIgniter?
$this->load->model ('Model_Name');


Question: What helpers in CodeIgniter?
You can to execute below command.

RCPT To:
This identifies the receipient of the email message. This command can be repeated multiple times for a given message in order to deliver a single message to multiple receipients.






Question: What is offical Website URL?
http://www.codeigniter.com


Question: List out different types of hook in Codeigniter?
  1. post_controller_constructor
  2. pre_controller
  3. pre_sytem
  4. post_sytem
  5. cache_override
  6. display_override
  7. post_controller



Friday, 18 September 2015

SMTP interview questions and answers

SMTP interview questions and answers



Question: Are email addresses case sensitive?
Yes, In email address before the @, are case senstive. So email address is case-sensitive.


Question: What is the meaning of return-path, reply-to and from?
From: <fromemail example.com="">
To: <you example.com="">
Reply-To: <replyto example.com="">
</replyto></you></fromemail>
Return-path: If email is failed to deliver OR bounced, then email will return to return-path.
Reply-to: If someone reply on email, then email will be goes to reply-to.
From: It denote from where which email-address came.


Question: What is the difference between ports 465 and 587?
Both are protocol.
465 is for SMTPS protocol, In this SSL encryption is started automatically before any SMTP level communication.
587 is for MSA protocol. SSL encryption may be started by STARTTLS command at SMTP level(if server supports). In this ISP does not filter server's EHLO reply.It helps to stop outgoing spam email.


Question: How to check if an email address exists without sending an email?
You can to execute below command.

RCPT TO: useremail@domain.com
This identifies the recipient of the email message. This command can be repeated multiple times for a given message in order to deliver a single message to multiple recipients.


Question: What are test email recipients?
OR
Which email address I can use for sending test email?

Following are testing email address
t11111@no-spam.ws
t11112@no-spam.ws
t11113@no-spam.ws
t11114@no-spam.ws
t11115@no-spam.ws

Check http://no-spam.ws/ for more email ids.


Question: How to check if smtp is working from commandline?
telnet {smtp_domain_name} {smtp_port}



Wednesday, 16 September 2015

jQuery Ajax Interview Questions and Answers for Experienced

jQuery Ajax Interview Questions and Answers for Experienced


Question: What is the difference between jQuery.get() and jQuery.ajax()?
$.get( "/ajax/add-user", { name: "Arun", company: "web-technology-experts-notes.in", gender:"Male" } );
$.get executes an Ajax request with using of GET Method.

$.ajax({
    type: "POST",
    url: "/ajax",
    data: "name=Arun&company=web-technology-experts-notes.in&gender=male",
    success: function(msg){
       console.log(msg); 
       
    }
});

$.ajax you full control over the Ajax request. In this you can use any method like GET or POST. I think you should use this only, if the other methods did not fulfill your requirement.
You can do lot of customization in this like caching and Ajax method etc


Question: What is the use of jQuery load method?
It is AJAX method which is used to load the data from a server and assign the data into the element without loading the page.


Question:What are the security issues with AJAX?
  1. Source code written in ajax easily visiable.
  2. Attrackers can send the the data to same API Call
  3. Attrackers can view the Request/Response in Ajax call.
  4. Attacker can view the full response and can hit and trial.



Question: How many types of ready states in ajax?
0: Request not initialized
1: Server connection established
2: Request received
3: Processing request
4: Request finished and response is ready


Question: List Some Popular Ajax Frameworks?.
  1. jQuery.
  2. script.aculo.us
  3. Prototype
  4. MooTools
  5. ExtJS
  6. Qooxdoo
  7. Yahoo! UI Library (YUI)
  8. MochiKit
  9. Midori
  10. The Dojo Toolkit



Question: What exactly is the W3C DOM?
The W3C Document Object Model (DOM) is defined by the W3C.
The DOM is a platform and language-neutral interface that allows programs and scripts to dynamically access/update the content of a document.


Question: What is the XMLHttpRequest object in AJAX?
It is way to update the web content from server without reloading the page.


Question: How can we abort the current XMLHttpRequest in AJAX?
use abort() function. For Example:
var xhr;    
xhr = $.ajax({
    url: 'ajax/get-user-details/user_id/3',
    success: function(data) {
        console.log(data);
    }
})
    
fn();

//Abort the Ajax call
if(xhr && xhr.readystate != 4){
  xhr.abort();  
}



Question: How to cancel all the active ajax call?
Every time you create an ajax request you should use a variable to store it, you can use array object to store multiple ajax.
Now you can use abort() function to abort each ajax call.


Question: How to debug Ajax call
You can use debug tools of browser.
like firebug in Mozilla.
Inspect element in Google Chrome

Question: How to convert an object to a string?
var javascriptObject = {name: "Web", "URL": "http://www.web-technology-experts-notes.in/"};
JSON.stringify(javascriptObject, null, 2);



Question: How to convert an string to a object?
var javascriptObject = '{name: "Web", "URL": "http://www.web-technology-experts-notes.in/"}';
JSON.parse(javascriptObject, null, 2);



Question: How can I add a custom HTTP header to ajax request with js or jQuery?
$.ajax({
    url: '/ajax/get-user-details/user_id/3',
    headers: { 'x-my-custom-header': 'some value' },
    success: function(data) {
        console.log(data);
    }
});



Question: How to determine if ajax timeout error comes?
$.ajax({
     url: '/ajax/get-user-details/user_id/3',
    type: "GET",
    dataType: "json",
    timeout: 1000,
    success: function(data) { 
        console.log(data);
     },
    error: function(x, t, m) {
        if(t==="timeout") {
            console.log("got timeout");
        } else {
            console.log(t);
        }
    }
});?


Question:How to send an https ajax call on http page?
Add the Access-Control-Allow-Origin header from the server
Access-Control-Allow-Origin: https://www.myexample.com




Tuesday, 15 September 2015

Apache Interview Questions and Answers

Apache Interview Questions and Answers

Question: What is Apache?
Apache is Web server application.


Question: What is use of Apache in Web Server?
Apache's role is all about communication over networks, and it uses the TCP/IP protocol (Transmission Control Protocol/Internet Protocol which allows devices with IP addresses within the same network to communicate with one another).


Question: From where Apache names comes?
The name "Apache" derives from the word "patchy" that the Apache developers used to describe early versions of their software development.


Question: What are feature of Apache?
Following are modules supported by Apache
  • mod_access, 
  • mod_auth, 
  • mod_digest, 
  • mod_auth_digest
  • Secure Sockets Layer 
  • Transport Layer Security support (mod_ssl), 
  • proxy module (mod_proxy)
  • URL rewriter (mod_rewrite)
  • custom log files (mod_log_config)
  • mod_ext_filter.



Question: Is Apache opensource?
Yes, It is


Question: Who is Initial Author of Apache?
Robert McCool


Question: In which language Apache is written?
'C' Language


Question: What is offical website of Apache?
httpd.apache.org


Question: Do I need Programming Skills to install Apache in my system?
No, You need not.

Wednesday, 9 September 2015

How to remove all classes using jQuery?

How to remove all classes using jQuery?


Question: How to remove class for single tag or single element with jQuery?
$(document).ready(function() {
    //Use this 
    $("#idName").removeAttr('className');

    //OR use this, both will be work same
    $("#idName").attr('class', '');
});

Any element having id="idName", Its class will be removed.
Element can p, div and p etc.
removeAttr is jQuery's inbuilt function, So you must call this function after loading the jQuery file.

$(document).ready() is used to identify jQuery file loaded.


Question: How to remove class for multiple tags in single line?
$(document).ready(function() {
    $(".className").removeAttr('className');
});

Any element having className class, "class" will be delete from html  tag.
Element can p, div & p etc.
removeAttr is jQuery's inbuilt function, So you must call this function after loading the jQuery file. $(document).ready();, is used to identify jQuery file loaded.


Question: How to remove class for single tag or single element without jQuery?
$(window).load(function() { 
    //Use this 
    document.getElementById('idName').className = '';
});

Any element having idName's class will be removed.
Element can pdiv and p etc.
$(window).load();, is used to identify html is fully loaded.


Tuesday, 8 September 2015

What are differences between $(document).ready and $(window).load?


What are differences between $(document).ready and $(window).load?

$(document).ready();
$(document).ready(function() {
 /** Add your code here **/
            


/** Add your code here **/

 console.log("HTML Document is fully load. HTML, javaScript and CSS is fully loaded.");
});

JavaScript code written inside $(document).ready will be called when HTML Document is fully loaded. It means JavaScript code will be called just after HTML, JavaScript & CSS is fully loaded.



$(window).load();
$(window).load(function() { 
 /** Add your code here **/
            


/** Add your code here **/


 console.log("Web page fully Loaded. HTML, Javascript, CSS, Images, Iframes and objects are fully loaded.");
});


JavaScript code written inside $(window).load will be called when Web page fully Loaded. It means JavaScript code will be called just after HTML, Javascript, CSS, Images, Iframes and objects are fully loaded.

Following document ready have same meaning and work as same.
$(document).ready(function(){

});
OR
$(function(){

});
OR
$(document).on('ready', function(){
})



Monday, 7 September 2015

How to Detect Request type in PHP

How to Detect Request type (GET OR Post ) in PHP

Question:How to Detect Request type (Get OR Post) in PHP?
$method = $_SERVER['REQUEST_METHOD'];
try {
    switch ($method) {
        case 'GET':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'POST':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'PUT':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'HEAD':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'DELETE':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        case 'OPTIONS':
            /** Add your code here **/
            
            /** Add your code here **/
            break;
        default:
            echo "$method method not defined";
            break;
    }
} catch (Exception $e) {
    echo $e->getMessage();
}



Question: How to get all post data in PHP?
$postData = array();
if(!empty($_POST)){
    $postData = $_POST;
}
print_r($postData );



Question: How to get all GET data in PHP?
$getData = array();
if(!empty($_GET)){
    $getData = $_GET;
}
print_r($getData );



Question: How to get Document root path in PHP?
echo $_SERVER['DOCUMENT_ROOT'];



Question: How to get Client Ip-Address in PHP?
echo $_SERVER['REMOTE_ADDR'];



Wednesday, 2 September 2015

How to export mysql query results to csv?

How to export mysql query results to csv?

To Learn OR understand the exporting mysql results in CSV.
Lets have below simple example.


  1. Step 1: Create a employee table
    CREATE TABLE IF NOT EXISTS `employee` (
      `id` int(11) unsigned NOT NULL,
      `first_name` varchar(100) DEFAULT NULL,
      `last_name` varchar(100) DEFAULT NULL,
      `gender` enum('m','f') DEFAULT NULL,
      `status` enum('0','1') NOT NULL COMMENT '0-Inactive, 1-Active',
      `address` varchar(255) DEFAULT NULL,
      `created_at` datetime DEFAULT NULL,
      `modified_at` datetime DEFAULT NULL
    ) ENGINE=InnoDB AUTO_INCREMENT=6;

  2. Add The records in employee table
    INSERT INTO `employee` (`id`, `first_name`, `last_name`, `gender`, `status`, `address`, `created_at`, `modified_at`) VALUES
    (1, 'Sunil', 'Malhotra', 'm', '1', '3020 new town, chandigarh', '2015-09-02 12:38:00', '2015-09-02 12:38:00'),
    (2, 'Anil ', 'Yadav', 'm', '1', '3020 new town, chandigarh', '2015-09-02 12:38:00', '2015-09-02 12:38:00'),
    (3, 'Aman ', 'Verma', 'm', '1', '3020 new town, chandigarh', '2015-09-02 12:38:00', '2015-09-02 12:38:00'),
    (4, 'Ram ', 'Singh', 'm', '1', '3020 new town, chandigarh', '2015-09-02 12:38:00', '2015-09-02 12:38:00'),
    (5, 'Arun', 'Kumar', 'm', '1', '3020 new town, chandigarh', '2015-09-02 12:38:00', '2015-09-02 12:38:00');
    

  3. Create a folder where you are going to export the csv file.
  4. Execute the Mysql Query.
    SELECT id,first_name,last_name,gender, STATUS, address FROM employee
    INTO OUTFILE 'E:/wamp/www/export/employee3.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    LINES TERMINATED BY '\n';

Tuesday, 1 September 2015

MySql replace NULL values with empty string without effecting Rowset

MySql replace NULL values with empty string without effecting Rowset

Question: What is NULL Value in MySQL?
NULL values means don't have any value. It is neither empty NOR it have any value.


Question: Give an Example which is give NULL Values in Query?
NULL values means don't have any value. It is neither empty NOR it have any values.
SELECT u.id, u.first_name,u.last_name,b.address1 FROM `users` as u LEFT JOIN billings as b on b.user_id=u.id order by u.id desc limit 5;
See Screenshot below:
Give an Example which is give NULL Values in Query



Question: How we can replace the null value with empty string?
We can use mysql IFNULL function to replace the null values with empty string. See Example:
SELECT IFNULL(null,"") as value 



Question: Give an Example to replace the NULL with empty string in mysql query?
We can use mysql IFNULL function to replace the null values with empty string. See Example:
SELECT u.id, u.first_name,u.last_name,IFNULL(b.address1,"") AS address1 FROM `users` as u LEFT JOIN billings as b on b.user_id=u.id  order by u.id desc limit 5; 

See Screenhot below:
Give an Example to replace the NULL with empty string in mysql query