Do you need a PHP programmer?
Use my services as a freelance PHP programmer by hiring me to do PHP programming on your website project.

I have built many custom PHP applications like project managers, classified ad websites and content management systems. I also work with open source applications such as WordPress, online shopping cart websites like Magento and develop content management systems like Joomla.

Monday, April 16, 2012

Replace space and all Illegal character on string - PHP

Hi, ,
Do you search for how to replace/remove illegal character (@#$%^&* etc) in your text string?
On this post I will share you simple code to make it.
This code will only allowed numbers (0-9) and characters (a-z).

my code :

<?php
    $string = 'by^#^we%%&bs.b_((logs+)&#@pot.()*)(~co!~@#_+m';
    $string = preg_replace('/[^0-9 a-z]+/i', '', $string);
    
    echo $string;
?>

And below is code for replace multiple space on your text string

<?php
    $string = 'by   webs.   blog  spot.  com';
    $string = str_replace(array(' '),array(''),$string);
    
    echo $string;
?>

Hope it will useful for all,
If you have questions or suggestions, please write your comment below.

Good Luck :)

No comments:

Post a Comment