tcorbeil Posted March 28, 2007 Share Posted March 28, 2007 Hello again. Someone gave me this script to replace special characters from a variable with "_".. $Subpage = ereg_replace("[^[:alpha:]]", "_", $Subpage); problem is that it also replaces numbers.. so if i have "$Subpage="Nintendo 64"; after $Subpage = ereg_replace("[^[:alpha:]]", "_", $Subpage); i would get a value of Nintendo___.. I would like to achieve a value of Nintendo_64.. Any advise would be much appreciated.. T. Link to comment https://forums.phpfreaks.com/topic/44653-stripping-charachters-from-a-variable/ Share on other sites More sharing options...
Orio Posted March 28, 2007 Share Posted March 28, 2007 Try: $Subpage = preg_replace("/[^a-z0-9]/i", "_", $Subpage); Orio. Link to comment https://forums.phpfreaks.com/topic/44653-stripping-charachters-from-a-variable/#findComment-216827 Share on other sites More sharing options...
WhatWhat Posted March 28, 2007 Share Posted March 28, 2007 You can just replace "alpha" with "alnum". Link to comment https://forums.phpfreaks.com/topic/44653-stripping-charachters-from-a-variable/#findComment-216830 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.