/    Sign up×
Community /Pin to ProfileBookmark

Escaping underscores in PHP

Okay, I’m using a form to automate information that I need to add to javascript files. The problem is I can’t find out to escape underscores. The JS function I have running cannot have spaces. So, I input underscores and have the function reset underscores to spaces on output (don’t ask). So, the information I need output doesn’t have any spaces at all. The problem that I have is that some places need an underscore directly after a variable. The underscore is seen as an extension of the variable when I write this. Can I escape the underscore? I’ve tried _ and __ to no avail.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 17.2004 — When it gets confusing, you can use "curly braces" to deliniate your variable names:
[code=php]
$variable_name = "test";
$_POST['something'] = $variable_name;
echo "Blah blah ${variable_name}_followed_by_underscores.";
echo "Blah blah ${_POST['something']}[followed by a bracket in the text.";
[/code]

...prints...
<i>
</i>Blah blah test_followed_by_underscores.
Blah blah test[followed by a bracket in the text.
Copy linkTweet thisAlerts:
@dreamcatcherNov 18.2004 — Can you not just use str_replace to remove the spaces?
×

Success!

Help @ephmynus 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...