Jump to content

Masking PHP Results?


justlukeyou

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.