Find us on twitterLike us on facebook
View Portfolio

PHP Library

Support Us

CSS Library

How to Remove Special Character from String in PHP | DevSocial.net How to Remove Special Character from String in PHP | DevSocial.net

free php scripts



Listings

How to Remove Special Character from String in PHP

How to Remove Special Character from String in PHP

How to Remove Special Character from String in PHP

We are given a string and the task is to remove special characters from string str in PHP. Below are the approaches to remove special characters from string in PHP:

Using str_replace() Method

The str_replace() method is used to remove all the special characters from the given string str by replacing these characters with the white space (” “).

Syntax:

str_replace( $searchVal, $replaceVal, $subjectVal, $count )

Example: This example illustrates the use of the str_replace() function to remove the special characters from the string.

<?php
  // PHP program to Remove 
  // Special Character From String

  // Function to remove the special 
  function RemoveSpecialChar($str) {

      // Using str_replace() function 
      // to replace the word 
      $res = str_replace( array( ''', '"',
      ',' , ';', '<', '>' ), ' ', $str);

      // Returning the result 
      return $res;
      }

  // Given string
  $str = "Example,to remove<the>Special'Char;"; 

  // Function calling
  $str1 = RemoveSpecialChar($str); 

  // Printing the result
  echo $str1; 
?>


Views: 6,250 / Downloads: 814 | Price: $0 | PHP / PHP Functions
Status: Active

|

You have no Listings. Create Listing.


Buy Ready made Web Apps  Buy Ready made Web Apps


Website Ranking Tools

classifieds24.net classifieds24.info classifieds24.org nywds.com https://www.globalclassifieds.org/ domainpaid.net devsocial.net paystopost.com paystopost.org https://www.101now.com https://www.newyorkconstructionco.com paystopost.org https://www.hirepros.org https://www.hirepros.info
EST: 2012 | © 2025 Devsocial.net | All Rights Reserved. [ + ][ y ]
SHARE:

Facebook

Twitter