Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Tuesday, 17 July 2018

Device Check / Mobile Detect PHP


Download Library From : http://aksolution.co.nf/wp-content/uploads/2018/07/Mobile-Detect.zip

require_once ‘Mobile-Detect/Mobile_Detect.php’; //include library file path
$detect = new Mobile_Detect;

$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? ‘tablet’ : ‘phone’) : ‘computer’); // display device 
name like : tablet,phone,computer.

$scriptVersion = $detect->getScriptVersion();
$devicedetail = $deviceType.’ ‘.$_SERVER[‘HTTP_USER_AGENT’];
//print device detail with some info.
echo “<pre>”;
print_r($devicedetail);

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Thursday, 14 June 2018

DropDown with multiple with open select option

//Multiple Select Drop Down Code
<div class="multiselect" id="multiple">
    <?php
    global $wpdb;
    $getid= $_GET['id'];
    $sql11 = "SELECT * FROM TABLENAME WHERE id = '$getid'";
    $result11 = $wpdb->get_results($sql11);
    $count1 = 1;
    foreach($result11 as $row11){?>                             
        <label>
            <input type="checkbox" id="chknote_<?php echo $count1; ?>" name="client_check[]" class="queAns trigger" data-trigger="hidden_fields_<?php echo $count1; ?>" data-trigger-one="hidden_fields_one<?php echo $count1; ?>"  value="<?php echo $count1; ?>" />
            <?php echo $count1; ?>. <?php echo $client->lastname;?>'s <?php echo $row11->goal; ?>
        </label>
    <?php $count1++;}?>
</div>

//multiple select drop down js script
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
jQuery(function() {
jQuery(".multiselect").multiselect();
});
jQuery.fn.multiselect = function() {
$(this).each(function() {
var checkboxes = $(this).find("input:checkbox");
checkboxes.each(function(){
var checkbox = $(this);
if (checkbox.prop("checked"))
checkbox.addClass("multiselect-on");
checkbox.click(function() {
if (checkbox.prop("checked")){
checkbox.addClass("multiselect-on");
}else{
checkbox.removeClass("multiselect-on");
}
});
});
});
};
</script>

//open selected option script
<script>
jQuery(function() {
  jQuery('.hidden').hide();
  jQuery('.trigger').change(function() {
var hiddenId = jQuery(this).attr("data-trigger");
if (jQuery(this).is(':checked')) {
  jQuery("#" + hiddenId).show();
} else {
  jQuery("#" + hiddenId).hide();
}

var hiddenId = jQuery(this).attr("data-trigger-one");
if (jQuery(this).is(':checked')) {
  jQuery("#" + hiddenId).show();
} else {
  jQuery("#" + hiddenId).hide();
}

  });
</script>

//open selected option html/php code
<?php
global $wpdb;
$getid = $_GET['getid'];
$sql="SELECT * FROM TableName WHERE id = '$getid'";
$result=$wpdb->get_results($sql);
$count = 1;
foreach($result as $row){?>
<span id="hidden_fields_<?php echo $count; ?>"  style="display: none;">

<?php echo $count; ?>. <?php echo $client->columnName;?>'s <?php echo $row->columnName; ?>:
<p><input type="hidden" name="goal_id[]" value="<?php echo $row->columnName; ?>" /></p>         
<div class="col-md-12"> Notes:
<textarea name="note[]"  class="custom-txt-area" id="hidden_<?php echo $count; ?>"></textarea>
</div>

</span>             
<?php  $count++;} ?>

//css for dropdown
<style>
.queAns{
    margin-right:5px !important;
}
.multiselect {
    width:33em;
    height:10em;
    border:solid 1px #c0c0c0;
    overflow:auto;
    padding:5px;
}

.multiselect label {
    display:block;
}

.multiselect-on {
    color:#ffffff;
    background-color:#d29714;
}
</style>
-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Wednesday, 13 June 2018

PHP Basic Functions - splits, strcmp, md5, ucwords, strstr, trim, number_format

<?php
//splits a string into an array
echo "splits a string into an array -- ";
$a="this is test string";
$m=str_split($a,4);
print_r($m);

//Compare two strings
echo "<br><br>";
echo "Compare two strings -- ";
$a="gfhgfhgfhfghgfhfghg";
$b="g";
if(strcmp($a,$b)==0)
{
echo "both are same";
}
else
{
echo "both are not same";
}

//calculates the MD5 hash of a string.
echo "<br><br>";
echo "calculates the MD5 hash of a string -- ";
$a="testString";
echo md5($a);

//Convert the first character of each word to uppercase
echo "<br><br>";
echo "Convert the first character of each word to uppercase -- ";
$a="this is test string";
echo ucwords($a);

//searches for the first occurrence of a string inside another string
echo "<br><br>";
echo "searches for the first occurrence of a string inside another string -- ";
$a="teststring";
echo strstr($a,'n');

//removes whitespace and other predefined characters from both sides of a string.
echo "<br><br>";
echo "removes whitespace and other predefined characters from both sides of a string -- ";
$a="   this isTest    ";
echo trim($a);

//formats a number with grouped thousands.
echo "<br><br>";
echo "formats a number with grouped thousands -- ";
$a = 1235655.9857985;
echo number_format($a,4);
?>

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Wednesday, 23 May 2018

Checkbox Show/Hide Hidden With Multiple Fields

<form action="#" method="POST">
  <div> Checkbox 1:
    <input type="checkbox" id="checkbox_one" name="Checkbox1" data-trigger="hidden_checkbox_one" class="trigger">
  </div>  <div id="hidden_checkbox_one" class="hidden"> This is hidden one:
    <input type="text" id="hidden_one" name="hidden">
  </div>
  <div> Checkbox 2:
    <input type="checkbox" id="checkbox_two" name="Checkbox2" data-trigger="hidden_checkbox_two" class="trigger">
  </div>
  <div id="hidden_checkbox_two" class="hidden"> This is hidden two:
    <input type="text" id="hidden_two" name="hidden">
  </div>
  <div> Checkbox 3:
    <input type="checkbox" id="checkbox_three" name="Checkbox3" data-trigger="hidden_checkbox_three" class="trigger">
  </div>
  <div id="hidden_checkbox_three" class="hidden"> This is hidden three:
    <input type="text" id="hidden_three" name="hidden">
  </div>
  <div> Checkbox 4:
    <input type="checkbox" id="checkbox_four" name="Checkbox4" data-trigger="hidden_checkbox_four" class="trigger">
  </div>
  <div id="hidden_checkbox_four" class="hidden"> This is hidden four:
    <input type="text" id="hidden_four" name="hidden">
  </div>
</form>

<script>
jQuery(function() {
  jQuery('.hidden').hide();
  jQuery('.trigger').change(function() { 
    var hiddenId = jQuery(this).attr("data-trigger");
    if (jQuery(this).is(':checked')) {
      jQuery("#" + hiddenId).show();
    } else {
      jQuery("#" + hiddenId).hide();
    }
  });
});
</script>

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Tuesday, 8 May 2018

PHP - Sending Emails using PHP


$to = "xyz@domainname.com";
$subject = "This is subject"; 
$message = "This is HTML message.";
$message .= "This is headline.";
$header = "From:info@domainname.com \r\n"; // domainname.com or domainname.co.in with domain name
$header .= "Cc:test@domainname.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
-------------------------------------------------

Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Wednesday, 18 April 2018

json_decode utf issue php


function dataJSON($inputs) {
 //This will convert ASCII/ISO-8859-1 to UTF-8.
 //Be careful with the third parameter (encoding detect list), because
 //if set wrong, some input encodings will get garbled (including UTF-8!)
 //$imput = mb_convert_encoding($inputs, 'UTF-8', 'ASCII,UTF-8,ISO-8859-1');
 //Remove UTF-8 BOM if present, json_decode() does not like it.
 if(substr($inputs, 0, 3) == pack("CCC", 0xEF, 0xBB, 0xBF)) $inputs = substr($input, 3); return $inputs;
}
$ReadPathJsonFile = site_url().'jsonFile.json';  // your json file path
$dataGet = file_get_contents($ReadPathJsonFile);

$jsonDecode = json_decode(dataJSON($dataGet), true);
//you can check the data
print_r($jsonDecode);
-------------------------------------------------

Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com 

Google Adsense

What is Google Adsense?

Google Adsense is a shortcut used by online publishers because it gives them access to a number of online advertisers. If you are an online publishers, advertisers will publish on your website. When the link to their site is clicked you earn money.

Google Adsense is not another get rich quick scheme like some people think. This tutorial is not here for those looking to make money online, this is to help understand the way Google Adsense operates and how businesses can work together to bring value to each other’s business. Making multiple websites and using Google Adsense will not bring in the money.

Our Comapny builds websites with value and encourage others to do the same. Why? Because it works and that is what makes the core fundamentals of business: A business that offers value, will in return earn money by bringing that value to others.

In order to get the best use from Google Adsense, your site has got to have purpose and value to it other than just looking to make money. A site needs to serve as a resource, entertainment, or tools that people can find useful.

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com