Showing posts with label Php. Show all posts
Showing posts with label Php. Show all posts

Saturday, 26 May 2012

Remove Special Characters from a String using preg_replace in Php

Hi All, in my earlier post i have written about how to remove special characters from mysql database. Sometime we only want to get result of an input string as a simple composition of alphabets and numbers and we want to remove all special characters in the given string.
In this case Php provide an easy function to do the needful. We can remove all special characters by using preg_replace.
Here is the simple syntax for it.

$result  = preg_replace('/[^a-zA-z0-9/s','',$string);
where $string is the string in which we want to filter special characters and $result is the output string without any special characters.

We can also use another Php function str_replace() to achieve the same if we know what all we have to remove. Here is the simple syntax for it.
str_replace(mixed search,mixed replace,mixed subject[,int & replace_count]);

More information on www.narendrarathore.com

Monday, 5 March 2012

Avoid ckeditor encoding

Hi
Ckeditor is a very good tool to publish data in drupal. Ckeditor can be applied on textarea and hence dull looking textarea can be changed to a good looking form.
There is a problem with Ckeditor that it take its own encoding and decoding while writing . Sometime it become hard to decode Ckeditor date in case of "'" , "-" and some special characters like these.
This problem can be solved by writing
config.htmlEncodeOutput = True;
in core/editor.js. Its default value is false. This is done to escape HTML in case when editor updates original input element.
This can also be changed in advance option field in ckeditor configuration UI. Write
config.htmlEncodeOutput = True;
in advance settings to avoid any special character encoding.
Queries and suggestions welcome.

More information on www.narendrarathore.com