HI, I want to create urls dynamically when i am inserting the new data to database. ForExample, If the story title is : What is new in DP? It should be converted as : what-is-new-in-dp.html It shouldn't allow any special characters in the URL. How can I do this?
<?php $title = "what's new in DP?"; $title = preg_replace("/[^a-z0-9-]/","",strtolower(str_replace(" ","-",$title))); echo $title.".html"; ?> PHP:
Its working. But the URL is ending the "-". for example : test-app-.html. i want to remove the "-" at end of the url. how can i do that?
<?php $title = "what's new in DP?"; $title = preg_replace("/[^a-z0-9-]/","",strtolower(str_replace(" ","-",$title))); if ( $title[strlen($title)-1] == "-" ) $title = substr($title,0,strlen($title)-1); echo $title.".html"; ?> PHP: