Solved

easy php print character

Posted on 2008-10-21
5
650 Views
Last Modified: 2012-05-05
I am using php to write a php file.  How would I fwrite a \' together without my php thinking I only want a '
I tried \\' but I don't think it is right... let me know if I am wrong.
0
Comment
Question by:newbe101
  • 2
  • 2
5 Comments
 
LVL 7

Assisted Solution

by:tg_wilk
tg_wilk earned 100 total points
ID: 22772855
If you only want a single quote to be written then look below. Otherwise please explain what you want to achieve.
fwrite($file,"'");//single quote written
//or
fwrite($file,'\'');//yet another single quote
 
 
 
//this would result in an error
fwrite($file,'\\'');
 
//this would write \'
fwrite($file,"\\'");

Open in new window

0
 

Author Comment

by:newbe101
ID: 22772865
I know, but how would I fwrite a \' to a php file for use in the new file?  I don't need the fwrite part, just the characters to print \' in a php file that will be using the \'
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 400 total points
ID: 22772881
You can avoid the escaping problems by using the chr() function. Backslash is ascii 92:

fwrite($f,chr(92)."'");

Open in new window

0
 
LVL 7

Expert Comment

by:tg_wilk
ID: 22772891

Lets say you want a file like this
 
<?php
$character = '\'';
?>
 
So you can fwrite
 
<?php
$content = <<<THEEND
<?php
$character = '\'';
?>
THEEND;
fwrite($file,$content);
?>
 
or if you want to stick with the single quotes:
 
<?php
$content = '<?php
$character = \'\\\'\';
?>';
fwrite($file,$content);
?>
 
Is that what you're looking for?

Open in new window

0
 

Author Comment

by:newbe101
ID: 22772896
cxr got it for me... thanks both of you.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question