justlukeyou Posted February 21, 2011 Share Posted February 21, 2011 Lets say I have a 'Red Widget' and 'Red Ball' in my database. At the moment I am searching for: phpproductdisplay.php?description=red - this displays both items. However, if I search for: phpproductdisplay.php?description=red%widget This displays only the red widget which works fine. However, I want to display the search terms on my site and in the title. So at the moment. I am displaying "red%widget". But I want to display "Red Widget". Is it possible to get 'Red Widget'? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 21, 2011 Share Posted February 21, 2011 urldecode() http://php.net/manual/en/function.urldecode.php then ucwords() http://php.net/manual/en/function.ucwords.php Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 21, 2011 Share Posted February 21, 2011 No, urldecode won't work in this situation, since it looks like the OP is searching for the string "red%widget" explicitly (that what is being typed in). You would just use [m]str_replace[m] to remove that character: <?php $str = "red%widget"; echo ucwords(str_replace('%',' ',$str)); ?> Ken Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted February 21, 2011 Author Share Posted February 21, 2011 Thanks kenrbnsn, If I put this code into my page will it only work on "red%widget"? Do I need to tell it to remove the % from whatever I put into the description. So it would work on : phpproductdisplay.php?description=red%ball <?php$str = "red%widget";echo ucwords(str_replace('%',' ',$str));?> Would I use something like? <?php$str = "'description'";echo ucwords(str_replace('%',' ',$str));?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 21, 2011 Share Posted February 21, 2011 I just gave an example of how you would used the function. In you script, you would use: <?php echo ucwords(str_replace('%',' ',$_GET['description'])); ?> Ken Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted February 21, 2011 Author Share Posted February 21, 2011 Hi ken, Thats brilliant, I did have a variation of this however it showed the '' so it was still messy. Many thanks for your brilliant help. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 21, 2011 Share Posted February 21, 2011 No, urldecode won't work in this situation, since it looks like the OP is searching for the string "red%widget" explicitly (that what is being typed in). You would just use [m]str_replace[m] to remove that character: <?php $str = "red%widget"; echo ucwords(str_replace('%',' ',$str)); ?> Ken quite right. thank you for pointing that out. Quote Link to comment 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.