Friday, 15 November 2019

How can I remove a particular value from an array in JavaScript with Example?


<!DOCTYPE html>
<html>  
<head>
    <title>How can I remove a particular value from an array in JavaScript with Example? -PHP Kishan</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" crossorigin="anonymous"></script>
    <script>  
    jQuery(document).ready(function(){
        orig_array = ['BattleGrounds', 'Fornite Battle Royale', 'League of Legends (LOL)', 'Counter-Strike: Global Offensive (CS: GO)', 'HearthStone', 'Minecraft', 'DOTA 2', 'Apex Legends', 'The Division 2', 'Splatoon 2', 'Rummy'];    //Ex: Game List
        document.getElementById("orig_array").innerHTML = orig_array;
      
      
        remove_game = orig_array.indexOf('Fornite Battle Royale'); // You can remove only one value (Game name)
        if (remove_game > -1) {
          orig_array.splice(remove_game, 1);
        }          
        document.getElementById("new_array").innerHTML = orig_array;
    });
    </script>
</head>
<body>
    <p><strong>Array Games List: </strong><br>=> <span id="orig_array"></span></p>  
    <p><strong>Reomve Game From List: </strong><br>=> Fornite Battle Royale</p>  
    <p><strong>New Array Games List: </strong><br>=> <span id="new_array"></span></p>  
</body>
</html>

Monday, 7 October 2019

How to redirect another webpage using JavaScript?



<!DOCTYPE html>
<html>   
<head>
    <title>How to redirect another webpage using JavaScript? -PHP Kishan</title>
    <script>   
        function new_Location(newurl) {       
            /* The wwindow.location method redirect to another webpage location. */
            window.location = newurl;
           
            // OR //
            /* The window.location.href() method redirect to another webpage location. */
            window.location.href = newurl;
           
            // OR //
            /* The window.location.assign() method loads a new location in the browser. */
            window.location.assign(newurl);
           
            // OR //
            /* The window.location.replace() method current location to redirect a new location in the browser. */
            window.location.replace(newurl);
        }

        var new_url = "https://phpkishan.blogspot.com/"; // Assigen New URL Location
    </script>
</head>
<body>
    <p>You can use any one method as per requirement for redirect your document location.</p>
    <input type="button" value="Redirect to new location" onclick="new_Location(new_url)">
</body>
</html>

Friday, 6 September 2019

How to prevent SQL injection in PHP?

<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    //unsafe data
    $unsafe_name = mysqli_real_escape_string($con, $_POST['fname']);
    $unsafe_email = mysqli_real_escape_string($con, $_POST['email']); 

    //safe data
    $safe_name = mysqli_real_escape_string($con, $_POST['fname']);
    $safe_email = mysqli_real_escape_string($con, $_POST['email']); 

    $sql = "INSERT INTO my_db (fname, email)  VALUES ('".$safe_name."', '".$safe_email."')";

    if (!mysqli_query($con,$sql)) {
        die('Error: ' . mysqli_error($con));
    }
    echo "1 record added";
    mysqli_close($con);  
}
?>

<form action="" method="post">
    Name: <input type="text" name="fname"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
</form>

Thursday, 5 September 2019

How to connect to mysqli database in php?


Create connection.php file and include all CRUD operation's file for connect database.

<?php
error_reporting(0);
$DB_HOST = 'localhost';
$DB_USER = 'root';
$DB_PASS = '';
$DB_NAME =  'mysql';
$conn = mysqli_connect($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);
// Check connection
if (!$conn) {
    echo "Failed to Connect to MySQL: " . mysqli_connect_error();
}else{
    echo "Success Connection to MySQL...!";
}
?>

Tuesday, 3 September 2019

How to Replace Text of the_content in WordPress

If you want to replace keywords and text in the_content? Add the following code to the functions.php file of your WordPress active theme OR in custom plugin.

<?php
function replace_text($text) {
    $text = str_replace('Have a coupon?', 'Haben Sie einen Gutschein?', $text);
    $text = str_replace('Apply Coupon', 'Gutschein anwenden', $text);
    $text = str_replace('Product', 'Produkt', $text);
    $text = str_replace('Price', 'Preis', $text);
    $text = str_replace('Coupon code', 'Gutschein Code', $text);
    $text = str_replace('Update Cart', 'Warenkorb aktualisieren', $text);
    $text = str_replace('Billing Details', 'Rechnungsdetails', $text);
    $text = str_replace('Additional Information', 'Zusätzliche Informationen', $text);
    $text = str_replace('Your order', 'Ihre Bestellung', $text);
    $text = str_replace('Shipping address', 'Lieferadresse', $text);
   
    return $text;
}
add_filter('the_content', 'replace_text',99);
?>