Help with PHP str_replace function

I have a search form input that has a Javascript placeholder of "Search whole site for..." to indicate where someone should type their search.  When the input box is clicked to type, the placeholder text is removed and teh user can type in their search keywords.  But, there are situations where we find that people are searching and it still has the "Search whole site for..." text in there, like "Search whole site for...grape jelly"

I am trying to use php to strip out the string "Search whole site for..." from the keywords and I am running into some trouble getting it to do the replacement with a blank.

This is what I have.

$keywords = $_GET['keywords'];
$keywords2 = str_replace($keywords, "", "Search whole site for...");
echo keywords2;

Open in new window

For some reason it is not recognizing the string and the result is the same as the input.  Where is the problem with this code?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
In the code snippet you need to use the dollar sign as the prefix for all PHP variables.

Please show us the HTML for this.  You may not need all of the code you have there!
Julian HansenCommented:
Instead of using Javasript for this why not use the HTML5 placeholder

<input type="text" name="keywords" placeholder="Search whole site for..." />

Open in new window

Supported on all major browsers back to IE9 - which should be the majority and saves having to use Javascript and avoids the problem you are having

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FourMatAuthor Commented:

The lack of a $ in the variable is just a typo when I entered into EE.  I was just using this code as an example to have someone verify that the syntax for the str_replace function was correct.

I was not aware of the placeholder attribute for HTML5.  That solves everything.  Thank you!
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.