?
Solved

easy php print character

Posted on 2008-10-21
5
Medium Priority
?
670 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Assisted Solution

by:tg_wilk
tg_wilk earned 400 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 1600 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

752 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