Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

remove all characters from string php?

make money online
letsplay Offline referral

Posts: 274
Joined: Jul 2013
Reputation: 1

Senior Member
Any idea how to remove all special characters from the string with PHP? I only want to leave numbers, letters and spaces?
marcus_avrelius Offline referral

Posts: 2,507
Joined: May 2013
Reputation: 109

Support Team
PHP Code:
$string str_replace(' ''-'$string); //replace spaces with dash symbol
$string preg_replace('/[^A-Za-z0-9\-]/'''$string); //remove all but numbers, letters and dash symbol
$string str_replace('-'' '$string); // remove dash symbol
$string trim($string" "); // trim spaces from the beginning and the end 
dswtechnologies Offline referral

Posts: 94
Joined: Aug 2015
Reputation: 1

$string = str_replace you can use this code with your own way.
Rapidsoft technologies Offline referral

Posts: 224
Joined: Sep 2015
Reputation: 1

Hi there,
function seo_friendly_url($string){
$string = str_replace(array('[\', \']'), '', $string);
$string = preg_replace('/\[.*\]/U', '', $string);
$string = preg_replace('/&(ampWink?#?[a-z0-9]+;/i', '-', $string);
$string = htmlentities($string, ENT_COMPAT, 'utf-8');
$string = preg_replace('/&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);/i', '\\1', $string );
$string = preg_replace(array('/[^a-z0-9]/i', '/[-]+/') , '-', $string);
return strtolower(trim($string, '-'));
damponting44 Offline referral

Posts: 536
Joined: Oct 2016
Reputation: 0

Senior Member
The str_replace() function replaces some characters with some other characters in a string.

Google this topic

User(s) browsing this thread: 1 Guest(s)