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'? Link to comment https://forums.phpfreaks.com/topic/228435-masking-php-results/ 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 Link to comment https://forums.phpfreaks.com/topic/228435-masking-php-results/#findComment-1177881 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 Link to comment https://forums.phpfreaks.com/topic/228435-masking-php-results/#findComment-1177895 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));?> Link to comment https://forums.phpfreaks.com/topic/228435-masking-php-results/#findComment-1177901 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 Link to comment https://forums.phpfreaks.com/topic/228435-masking-php-results/#findComment-1177906 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. Link to comment https://forums.phpfreaks.com/topic/228435-masking-php-results/#findComment-1177909 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. Link to comment https://forums.phpfreaks.com/topic/228435-masking-php-results/#findComment-1177915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.