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 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
$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 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 :: laravel 8 previous page 
Php :: php check method of http request 
Php :: php get file extension from filename 
Php :: store file into specific directory laravel using storage facade 
Php :: how to show validation error in laravel blade 
Php :: get page title wordpress 
Php :: php get string after character 
Php :: php if url contains 
Php :: laravel seed migrate 
Php :: laravel route group middleware prefix 
Php :: php version 
Php :: macos install php 7.4 
Php :: check email exist or not wordpress 
Php :: phpexcel set font color 
Php :: array_sum in multidimensional array php 
Php :: ucfirst() php 
Php :: delete image from public folder in laravel 
Php :: php get latest file in directory 
Php :: remove http / https from link php 
Php :: php dom add class to element 
Php :: select join distinct 
Php :: php foreach string char 
Php :: set nav link active on the basis of route laravel 
Php :: webmin forgot password 
Php :: php error reporting show warnings 
Php :: php get only numbers from string 
Php :: laravel validation time hours minutes format 
Php :: dequeue beaver buillder script wordpress 
Php :: php pdo get database name 
Php :: php check if input is date 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =