Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php strip out special characters

function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

   return preg_replace('/[^A-Za-z0-9-]/', '', $string); // Removes special chars.
}
Comment

Remove Special Character in PHP

phpCopy<?php
function RemoveSpecialChar($str)
{
    $res = preg_replace('/[0-9@.;" "]+/', '', $str);
    return $res;
}
$str = "My name is  hello and email hello.world598@gmail.com;";
$str1 = RemoveSpecialChar($str);
echo "My UpdatedString: ", $str1;
?>
Comment

Remove special characters in php

function removeSpecialChar($string) 
		{
			$string = strtolower($string);
			$string = preg_replace('/[^da-z ]/i', '', $string);// Removes special chars.
			$string = str_replace(' ', '-', $string); // Replaces all spaces with underscore.
			return strtolower($string);
		}
Comment

Remove Special Character in PHP

phpCopy<?php
$str = "@@HelloWorld";
$str1 = substr($str, 1);
echo $str1 . "

";
$str1 = substr($str, 2);
echo $str1;
?>
Comment

Remove Special Character in PHP

phpCopy<?php
$mainstr = "<h2>Welcome to <b>PHPWorld</b></h2>";

echo "Text before remove: 
" . $mainstr;

echo "

Text after remove: 
" .
    str_ireplace(array('<b>', '</b>', '<h2>', '</h2>'), '',
    htmlspecialchars($mainstr));
?>
Comment

Remove Special Char PHP

<?php
function RemoveSpecialChar($str)
{
    $res = preg_replace('/[0-9@&^\%()#$!][}{*'".;" "]+/', ' ', $str);
    return $res;
}
$str = "My name is  hello and)(**&&^%$$#@! em[ail he}ll'o.world{59}8@gmail.com;";
$str1 = RemoveSpecialChar($str);
echo $str1;
?>
Comment

Remove Special Character in PHP

phpCopy<?php
$mainstr = "This is a sim'ple text;";
echo "Text before remove: 
" . $mainstr, "
";
$replacestr = remove_sp_chr($mainstr);
function remove_sp_chr($str)
{
    $result = str_replace(array("#", "'", ";"), '', $str);
    echo "

Text after remove: 
" . $result;
}
?>
Comment

Remove Special Character in PHP

phpCopy<?php
$str = "geeks";
$str = ltrim($str, 'g');
echo $str;
?>
Comment

Remove Special Character in PHP

phpCopy<?php
$mainstr = "@@PHP@Programming!!!.";
echo "Text before remove:
" . $mainstr;
echo "

Text after remove: 
" . trim($mainstr, '@!.');
?>
Comment

Remove Special Character in PHP

phpCopy<?php
$string = "DelftStack is a best platform.....";
echo "Output:  " . rtrim($string, ".");
?>
Comment

Remove Special Character in PHP

phpCopy<?php
$strTemplate = "My name is :name, not :name2.";
$strParams = [
    ':name' => 'Dave',
    'Dave' => ':name2 or :password',
    ':name2' => 'Steve',
    ':pass' => '7hf2348', ];
echo "
" . strtr($strTemplate, $strParams) . "
";
echo "
" . str_replace(array_keys($strParams), array_values($strParams), $strTemplate) . "
";


?>
Comment

Remove Special Character in PHP

phpCopy<?php
$str = "ei all, I said eello";
//$trans = array("h" => "-", "hello" => "hi", "hi" => "hello");
echo "Output:  " . strtr($str, "e", "h");
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php first 20 words 
Php :: strpos in python 
Php :: .htaccess for laravel in hostinger 
Php :: laravel scaffolding 
Php :: messed up pagination laravel 
Php :: laravel simplexmlelement xml add attribute 
Php :: laravel collection implode 
Php :: mobile number validation in laravel 8 
Php :: composer create-project --prefer-dist laravel/laravel blog 
Php :: carbon in laravel 
Php :: add seconds to datetime carbon 
Php :: add array to another array in laravel collection 
Php :: join 2 tables laravel 
Php :: get the page content in wordpress 
Php :: errno: 150 foreign key constraint is incorrectly formed laravel 8 
Php :: how to get all rows from a table except some rows in laravel 
Php :: php force image refresh 
Php :: validate time in laravel 
Php :: convert post name to id 
Php :: laravel pass view with data 
Php :: codeigniter form_validation email 
Php :: last 6 digits of string laravel 
Php :: php remove specific element from array 
Php :: check if all values in array are equal php 
Php :: Get date without time in laravel 
Php :: Laravel Session using Global Session php function 
Php :: laravel migration change column length 
Php :: in loop how add string by comma in php 
Php :: calculate string php 
Php :: smtp server xampp 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =