I was trying to echo the quotation " in a string, but I realized it wasn't going to work the way I thought it would, does anybody know how to do this?
Thanks

Recommended Answers

All 11 Replies

I was trying to echo the quotation " in a string, but I realized it wasn't going to work the way I thought it would, does anybody know how to do this?
Thanks

You need to escape it:

echo "This is a quote \" and it has been escaped";

If that isn't what you mean, just post your code and we'll have a peek. :)

so you're saying that will print:

This is a quote " and it has been escaped

with the quotation in there, or not?
Thanks

so you're saying that will print:

This is a quote " and it has been escaped

with the quotation in there, or not?
Thanks

The quote will be there.

IDK, it didn't seem to work with this piece of code I have:

<?php
    echo "<a href="gallery.php?value=$prevValue">Previous</a>  </br>  <a href="gallery.php?value=$nextValue" >Next</a>";
?>

You forgot to escape the quotes:

<?php
    echo "<a href=\"gallery.php?value=$prevValue\">Previous</a>  </br>  <a href=\"gallery.php?value=$nextValue\" >Next</a>";
?>

Yeah I knew that I didn't put them in, cause I tried it and it didn't work.

Try this

<?php
echo '<a href="gallery.php?value='.$prevValue.'">Previous</a></br>';
echo '<a href="gallery.php?value='.$nextValue.'">Next</a>';
?>

Yeah I knew that I didn't put them in, cause I tried it and it didn't work.

What kind of error does it give you?

Member Avatar for iamthwee

What kind of error does it give you?

stymiee, your code worked for me. I was able to see the quotation marks? Does it matter what version of php the person is using. Perhaps, that might be causing the problems?

stymiee, your code worked for me. I was able to see the quotation marks? Does it matter what version of php the person is using. Perhaps, that might be causing the problems?

That shouldn't make a difference as it is very basic PHP. Might have been a caching problem with the browser is my guess.

You almost always have to hit reload on pages you're working on.

If your programming environment uses color highlighting, it can sometimes give you a clue as to if you forgot to escape the quotation marks. Notice the posts above by Dark_Omen and stymiee. See how the text in the later post is all red between quotes while the one above has blue? The correctly escaped post is all red while other is not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.