looking for basic php help

yhelothar

Lifer
Dec 11, 2002
18,409
39
91
How do I use ' in my text without messing up the coding? They seem to be open and closing tags for php.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
<?php echo "This is a single quote ' " ; ?>

Use double quotes around it.
 

yhelothar

Lifer
Dec 11, 2002
18,409
39
91
:confused:
well I figured out an alternative by using an apostrophe look-alike
´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'´'
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
alternatively you can escape the quote simply by putting a backslash before it.


echo 'y h\'elo t\'har\', o\'mg \'t\'har is quote\'s all ovar!';


edit: this works for both single and double quotes. Also, you can use the echo <<< ENDOFECHO; syntax if you have a large block of text with a ton of quotes. This can be especially usefull for echoing javascript to the browser.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: Zugzwang152
alternatively you can escape the quote simply by putting a backslash before it.


echo 'y h\'elo t\'har\', o\'mg \'t\'har is quote\'s all ovar!';


edit: this works for both single and double quotes. Also, you can use the echo <<< ENDOFECHO; syntax if you have a large block of text with a ton of quotes. This can be especially usefull for echoing javascript to the browser.

Just make sure the quotes you're escaping match the quotes you're using around it. Other than that, your way is probably better.

For example,....