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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.