/    Sign up×
Community /Pin to ProfileBookmark

escaping characters

hi now i know why this doesnt work

$handle = @fopen(“users.txt”, “a”);
if(!$handle)
{die(“Error opening file to writing”);}
fwrite($handle, “,'”.$username.”‘”);
fclose($handle);

but when i try to escape the ,’ or the ‘ it doesnt work what am i doing wrong could someone show me the correct way to get this working?

this is the error i get, i presume its becuase they are unescaped, Parse error: parse error, expecting `‘,” or `‘;” in /home/richardt/public_html/james/register.php on line 25

Thanks
Rich

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@AdamGundryApr 15.2004 — I'm not entirely sure what you are trying to do, but this is how you would escape that string:

fwrite($handle, ",'".$username."'");

Adam
Copy linkTweet thisAlerts:
@96turnerriauthorApr 15.2004 — ok i am trying to write

,'USERNAME' to the file users.txt

thanks for your reply i will try that
Copy linkTweet thisAlerts:
@96turnerriauthorApr 15.2004 — :mad: it wasnt that at all i forgot the damn ; at the end of one line grrrrrrrr, thanks all the same adam
×

Success!

Help @96turnerri spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...