Category Archives: PHP Scripts

It contains PHP Scripts that I learn newly.

How to replace a content using regular expression search in php?

It’s as follows :-

 <?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}1,$3';
echo preg_replace($pattern, $replacement, $string);
?> 
O/p :-
April1,2003

How to replace a content in php?

It’s as folllows : –


<?php
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
?>

Add one day additional to a date in php

It’s as follows : –

 

$year=2013;
$month=04;
$date=12;
$newdate=date('Y-m-d H:i:s', strtotime($year."-".$month."-".$date." 00:00:00" . ' + 1 day'));

O/p :-

$new date will be “2013-04-13 00:00:00

how to Select All / Deselect All options in multiple select box using java script?

It’s as follows :

 

function listbox_selectall(listID, isSelect) {
        var listbox = document.getElementById(listID);
        for(var count=0; count < listbox.options.length; count++) {
            listbox.options[count].selected = isSelect;
    }
}

 

onclick="listbox_selectall('countryList', true)" //select all the options

(or)

onclick="listbox_selectall('countryList', false)" //deselect all the options

how to get multiple selected values and items from listbox using javascript?

It’s as follows :

 

var src = document.getElementById('leftSelect');
var selected = [];
var options = src.options.length;
for (var i=0; i < options ; i++)
{
     if(src.options[i].selected)
     {
          alert(src.options[i].text);
          alert(src.options[i].value);
     }
}

 

<html>
<select id="leftSelect" onclick="" name="edu_quli" size="10" multiple="multiple">
<option value="10th">10th</option>
<option value="+2">+2</option>
<option value="Any Graduation">Any Graduation</option>
<option value="Any Post Graduation">Any Post Graduation</option>
<option value="Arts Post-Graduation">Arts Post-Graduation</option><option value="Science Post-Graduation">Science Post-Graduation</option>
<option value="Commerce Post-Graduation">Commerce Post-Graduation</option>
<option value="Technical/Professional Post-Graduation">Technical/Professional Post-Graduation</option>
<option value="Management Post-Graduation">Management Post-Graduation</option>
<option value="Other Post-Graduation">Other Post-Graduation</option>
<option value="Diploma">Diploma</option>
<option value="Others">Others</option>
</select>
</html>