ShoeLace1291 Posted November 8, 2010 Share Posted November 8, 2010 I've read up on the urlendcode functions in the PHP user manual, but it's all very confusing. How would I convert a simple string that was creeated by a text input to a format such as this: site.com/articles/Some-URI Quote Link to comment https://forums.phpfreaks.com/topic/218075-string-to-uri-format/ Share on other sites More sharing options...
OldWest Posted November 8, 2010 Share Posted November 8, 2010 Can you post an example of a string you are referring to? Quote Link to comment https://forums.phpfreaks.com/topic/218075-string-to-uri-format/#findComment-1131643 Share on other sites More sharing options...
trq Posted November 8, 2010 Share Posted November 8, 2010 Can we have an example of what the inputted data might look like? Quote Link to comment https://forums.phpfreaks.com/topic/218075-string-to-uri-format/#findComment-1131644 Share on other sites More sharing options...
ShoeLace1291 Posted November 8, 2010 Author Share Posted November 8, 2010 Basically if a user chose a title such as PHP Freaks Is Awesome, i would want it to output php-freaks-is-awesome Quote Link to comment https://forums.phpfreaks.com/topic/218075-string-to-uri-format/#findComment-1131646 Share on other sites More sharing options...
trq Posted November 8, 2010 Share Posted November 8, 2010 So replace spaces with - using str_replace. Quote Link to comment https://forums.phpfreaks.com/topic/218075-string-to-uri-format/#findComment-1131649 Share on other sites More sharing options...
OldWest Posted November 8, 2010 Share Posted November 8, 2010 Here is some example code I wrote using an array to do this job for you. You can process your strings in various ways, but this will produce the desired result: <?php $search = array(' '); $replace = array('-'); $subject = 'This is a string with spaces between each word.'; echo str_replace($search, $replace, $subject); ?> Quote Link to comment https://forums.phpfreaks.com/topic/218075-string-to-uri-format/#findComment-1131659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.