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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.