gevans Posted November 21, 2008 Share Posted November 21, 2008 Hey guys, I'm part way through building a cms. The cms can make pages that are redirected using .htaccess file All the URL are as follows http://www.mydomain.com/an_added_page htaccess takes an_added_page and loads=> index.php?p=an_added_page The filename is made from the page title, so An Added Page gets converted to an_added_page and stored. I want the users to be able to write anything in the page title, but store a version of it with [a-z0-9_] what's the best way to do this?? <?php //Example $title= "This's the page title!"; //Desired string = "this_s_the_page_title" if(!ereg("^[a-zA-Z0-9_]+$", $title)){ //string isn't fine, need to strip out anything that isn't a-z, 0-9 or and udnerscore } else { //string's fine $title = str_to_lower($title); } ?> Hope all that makes sense...... Link to comment https://forums.phpfreaks.com/topic/133647-solved-strip-certain-characters/ Share on other sites More sharing options...
gevans Posted November 21, 2008 Author Share Posted November 21, 2008 Think I've got it sorted myself... $title = "This's my page!! content, here.."; $title = ereg_replace("[^A-Za-z0-9 ]", "", $title); $title = strtolower(str_replace(" ", "_", $title)); echo $title; //prints thiss_my_page_content_here Link to comment https://forums.phpfreaks.com/topic/133647-solved-strip-certain-characters/#findComment-695303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.