0

I have an error on the following code:

$name = "Bush Dvd Player";

print "<a href='?name".print str_replace(' ', '-', $name).".html' >Previous</a>";

On the page is shows the following:

Car-Parts-and-Accessories however not in a url format?

0

2 Answers 2

4

str_replace() returns a string that will be concatenated to the output string, therefore there is no need for the additional print, so just omit it:

print "<a href='?name" . str_replace(' ', '-', $name) . ".html' >Previous</a>";

Your old code would print out the result of str_replace, followed by the concatenation of the first string literal, along with the return value of print str_replace(' ', '-', $name), and then then 2nd string literal.

Sign up to request clarification or add additional context in comments.

Comments

0

What happens is your inner print statement is evaluated before the outer print statement. To fix this you should simply remove the second print.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.