Solved

easy php print character

Posted on 2008-10-21
5
631 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now