Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not sure how to use "

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
0
0
US

Hello, I am new to PHP and I am writeing information to a text file. In the text file I have to have a quote for the log, so in the log file I have to have a single ". I cannot get this to work. I get errors when I use "\ because it looks somthing like this ""\". When I use this I get an error with fputs. Can someone help me out.
Thanks


<?
$filename ="c:\zzzz.txt";

$myFile= fopen($filename,'a+');
if(! $myFile){
print ("File could not be opened.");
exit;
}
$string = "\""

fputs($myFile, $string);
fclose($myFile);
?>
 
try moving the \ over one. You can make php recognize "" as a symbol rather than syntax with \ in FRONT of the symbol. ie.

"\"" the second is now just a simple " and not part of missing syntax.
 
I recommend using singlequotes to delimit your strings:

Code:
<?
$filename = 'c:\zzzz.txt';     
                               
$myFile= fopen($filename,'a+');    
if(! $myFile){            
print ('File could not be opened.'); 
exit; 
} 
$string = [red]'[/red]"[red]'[/red];

fputs($myFile, $string);     
fclose($myFile);        
?>

In general, I use single quotes to delimit all my strings. There are two exceptions to this rule:[ul][li]when I have to output a newline, tab or other character that must be represented as an escaped string, the \n or \t has to be inside doublequotes. This is because single-quoted strings are not interpolated.[/li][li]Delimiting SQL queries -- many SQL interpreters require singlequotes around strings, so I use doublequotes around the entire query.[/li][/ul]



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top