Jump to content

I think they are called escape characters


comports

Recommended Posts

HI All,

I need some help with a very small issue. I have some php code that reads stuff (text) from a txt file and then displays it on a page. All this is fine until I use the ' (apostrophe) character which then breaks the code. I guess it would be the same for " and $ etc..

I have tried preceding it with a \ (backslash) but that did nothing to help..

Any clues.?

Thanks
Ash
Thanks Chris but I don't follow that.. In my text file have for example:

[quote]Sometimes it works but sometimes it dont..[/quote]

but I want it print out the "dont" as don't with the apostrophe. If i change my txt file to read "Sometimes it works but sometimes it don't." it breaks because of the '.

Is there no simple way to include these and just display as a string. i.e. "don\'t" (even thought that don't work).

Thanks
Ash
code?

basically... what you want to do, is when its coming out of the file, you want to $var=addslashes($var); this protects it from all them characters interfering with the code
then when displaying, you echo stripslashes($var); this takes all the slashes out, so you dont have to see them.
Thanks Again Chris.

It seems to work if you "hard code" the string but I'm calling it from a text file.

The only output I get is "Sometimes it works and sometimes it don\'t"

My code is
[code]
$r_array=file("../cane-corso/images/text/".substr($files[$num],0,-4).'.txt');
echo $mQuotePath[0];
$query = $r_array[0];
parse_str($query);
$string=$text;
addslashes($string);
echo $string;[/code]

What am I doing wrong here.

Thanks
Try using the function [url=http://www.php.net/htmlentities]htmlentites()[/url] instead:
[code]<?php
$r_array=file("../cane-corso/images/text/".substr($files[$num],0,-4).'.txt');
echo $mQuotePath[0];
$query = $r_array[0];
parse_str($query);
$string=$text;
echo htmlentities($string,ENT_QUOTES);
?>[/code]

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.