Solved

easy php print character

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 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 …

717 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