Solved

easy php print character

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

733 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