Hi,
you can search non-alpha numeric characters by simple adding a negation regex charactor in the regex string (^).
below is the Example
preg_replace('/[^A-Za-z0-9_]/'
Thanks
A self-motivated, multi-domain, hardworking, responsible and solutions-orientated JAVA, J2EE, Spring 4, HTML 5, CSS 3, JavaScript, ES6, Typescript, AngularJS 1.4, jQuery 1.8, PHP 5, Shell Script, PL SQL, MySQL, Google App Engine, Google Datastore, JPA, Cucumber BDD Professional with more then 8+ Years of IT experience in a various IT stages including Design, developing, Unit testing and enhancement and 24*7 support application.
Configure HTML/JavaScript
Thursday, January 20, 2011
Searching non alpha numeric character through REGEX through PHP
Monday, December 20, 2010
Checking the Request is Ajax
//function to check if the request is made through ajax
function isAjax() {
return (isset($_SERVER['HTTP_X_
($_SERVER['HTTP_X_REQUESTED_
}
}
Thursday, December 9, 2010
managing multiple Databases in php
private $conn;
private $intranetdb = 'jprod';
private $metricsdb = 'metrics_prod';
private function __costructor(){
}
static function intranetDb(){
return 'jprod';
}
static function metricsDb(){
return 'metrics_prod';
}
static function makeConnection($host, $username, $password){
return $this->conn = mysql_connect($host, $username, $password);
}
static function prodConnection(){
$prod_dbhost = 'localhost1';
$prod_dbuser = 'jroot';
$prod_dbpass = 'joomla1';
/*
$prod_dbhost = 'localhost';
$prod_dbuser = 'root';
$prod_dbpass = '';
*/
$prod_conn = mysql_connect($prod_dbhost, $prod_dbuser, $prod_dbpass) or die ('Error connecting to mysql');
return $prod_conn;
}
static function metricsConnection(){
$dbhost = 'localhost2';
$dbuser = 'jroot';
$dbpass = 'joomla1';
/*
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
*/
$db = 'metrics_prod';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
return $conn;
}
static function closeConnection($resource){
return mysql_close($resource);
}
static function freeResult($result){
return mysql_free_result($result);
}
}
Friday, November 12, 2010
file copy from url in java
public int copyfile(String filesToTransfor[]) {
int oneChar, count = 0;
if (filesToTransfor.length < 1) {
System.err.println("Two file path is required to complete the process");
System.exit(1);
}
try {
URL url = new URL(filesToTransfor[0]);
System.out.println("Opening connection to " + filesToTransfor[0] + "...");
URLConnection urlC = url.openConnection();
// Copy resource to local file, use remote file
// if no local file name specified
InputStream is = url.openStream();
// Print info about resource
System.out
.println("Copying resource (type: " + urlC.getContentType());
// Date date=new Date(urlC.getLastModified());
// System.out.println(", salesnet file modified on: " + date.toString() + ")...");
System.out.flush();
FileOutputStream fos = null;
if (filesToTransfor.length < 2) {
String localFile = null;
// Get only file name
StringTokenizer st = new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens())
localFile = st.nextToken();
fos = new FileOutputStream(localFile);
} else
fos = new FileOutputStream(
while ((oneChar = is.read()) != -1) {
fos.write(oneChar);
count++;
}
is.close();
fos.close();
System.out.println(count + " byte(s) copied");
} catch (MalformedURLException e) {
System.err.println(e.toString(
} catch (IOException e) {
System.err.println(e.toString(
}
return count;
}
Saturday, September 4, 2010
javascript private members of a object
Private Members in JavaScript
Douglas Crockford
www.crockford.com
JavaScript is the world's most misunderstood programming language. Some believe that it lacks the property of information hiding because objects cannot have private instance variables and methods. But this is a misunderstanding. JavaScript objects can have private members. Here's how.
Objects
JavaScript is fundamentally about objects. Arrays are objects. Functions are objects. Objects are objects. So what are objects? Objects are collections of name-value pairs. The names are strings, and the values are strings, numbers, booleans, and objects (including arrays and functions). Objects are usually implemented as hashtables so values can be retrieved quickly.
If a value is a function, we can consider it a method. When a method of an object is invoked, the this variable is set to the object. The method can then access the instance variables through the this variable.
Objects can be produced by constructors, which are functions which initialize objects. Constructors provide the features that classes provide in other languages, including static variables and methods.
Public
The members of an object are all public members. Any function can access, modify, or delete those members, or add new members. There are two main ways of putting members in a new object:
In the constructor
This technique is usually used to initialize public instance variables. The constructor's this variable is used to add members to the object.
function Container(param) {
this.member = param;
}
So, if we construct a new object
var myContainer = new Container('abc');
then myContainer.member contains 'abc'.
In the prototype
This technique is usually used to add public methods. When a member is sought and it isn't found in the object itself, then it is taken from the object's constructor's prototype member. The prototype mechanism is used for inheritance. It also conserves memory. To add a method to all objects made by a constructor, add a function to the constructor's prototype:
Container.prototype.stamp = function (string) {
return this.member + string;
}
So, we can invoke the method
myContainer.stamp('def')
which produces 'abcdef'.
Private
Private members are made by the constructor. Ordinary vars and parameters of the constructor becomes the private members.
function Container(param) {
this.member = param;
var secret = 3;
var that = this;
}
This constructor makes three private instance variables: param, secret, and that. They are attached to the object, but they are not accessible to the outside, nor are they accessible to the object's own public methods. They are accessible to private methods. Private methods are inner functions of the constructor.
function Container(param) {
function dec() {
if (secret > 0) {
secret -= 1;
return true;
} else {
return false;
}
}
this.member = param;
var secret = 3;
var that = this;
}
The private method dec examines the secret instance variable. If it is greater than zero, it decrements secret and returns true. Otherwise it returns false. It can be used to make this object limited to three uses.
By convention, we make a private that parameter. This is used to make the object available to the private methods. This is a workaround for an error in the ECMAScript Language Specification which causes this to be set incorrectly for inner functions.
Private methods cannot be called by public methods. To make private methods useful, we need to introduce a privileged method.
Privileged
A privileged method is able to access the private variables and methods, and is itself accessible to the public methods and the outside. It is possible to delete or replace a privileged method, but it is not possible to alter it, or to force it to give up its secrets.
Privileged methods are assigned with this within the constructor.
function Container
Thursday, June 24, 2010
learning spanish
few words
I -> estoy
Excuse me -> perdone senora
good morning -> buenos dias
if not morning -> buenos noches
how are you feeling -> como esta?
i am fine -> Estoy ben.
what is your name -> como iiama
my name is anirudda -> me iiama aniruddha
its nice to meet you -> mucho gusto
Thanks