This question already has answers here:
Magic quotes in PHP
(12 answers)
Closed 8 years ago.
I am working on a website and I have a php editor that automatically adds \ to certain things. I was aware of the stripslashes() function and I know it can be used in a way such as: stripslashes($test) but I am including something and I do not know how to strip the slashes from the Page I am including. Here is my include code that I am using:
<?php include $_SERVER['DOCUMENT_ROOT']."/newseditor/BlogTitle.php"; ?>
So how would I stripslashes from this? Thanks for reading and I appreciate all help I recieve.
You are suffering from PHP's magic quotes, and here is how to turn it off:
http://www.php.net/manual/en/security.magicquotes.disabling.php
Related
This question already has answers here:
How do I escape an exclamation mark in bash?
(4 answers)
Closed 2 years ago.
I want to pass a string to a php script which contains ! character. Like this
php cfg.php --name=smtppass --set="MYW!ORD"
But I get this error
bash: !ORD: event not found
On the other hand, if I pass "MYW\!ORD", I see this string is set when I query the file
smtppass MYW\!ORD
Any idea to fix that?
You could pass it like this:
php cfg.php --name=smtppass --set="MYW"'!'"ORD"
or a more lazy way would be to use single quotes.
php cfg.php --name=smtppass --set='MYW!ORD'
This happens because of Bash's history expansion, which is sometimes very dangerous, you could turn this feature off by typing set +H.
This question already has answers here:
PHP: Variables in a Postgresql Query
(2 answers)
Closed 3 years ago.
I’m working on a project where I need to use postgresql to update info. I need to take
Martin’s chik ‘n’ chips
And make change it to
Martin\’s chik \’n\’ chips
How would I do this? I’ve looked at other posts, and found out to use substr() to create the new string and strpos() to find the ‘s, and even setting a new variable to keep the position of the previous ‘
Edit: thanks everyone, clearly didn’t do enough research!
If in PHP:
Check out str_replace(). e.g.
$text = "Martin’s chik ‘n’ chips";
$apostrophe = array("'","`","‘","’");
$newtext = str_replace($apostrophe,"\'",$text);
In this specific example, if you don't have any of the 'fancy' apostrophes, check out addslashes() as this will solve everything for you
This question already has answers here:
Can I create a PHP function that I can call without parentheses?
(6 answers)
Closed 6 years ago.
all php functions need () in the end. However, exit doesnt need that.
Can I create a function manually, which I can later execute without () ?
Even more, If I have full access to php installation?
p.s. please dont tell me answers "exit is not function" or etc (My question is not if "exit" is function or not). I want to know HOW TO ACHIEVE like that.
No you can't. You have to edit Base of PHP language to accomplish this.
exit , echo , print and etc are not function .
This question already has answers here:
php echoing angle brackets
(4 answers)
Closed 9 years ago.
Example data in my database:
blabla<blabla
I use phpmyadmin and can see that the data has been input successfully.
However when I try to display the data what I get is:
blabla NOT blabla<blabla
In other words, everything after the < symbol does not display.
<?
while ($mouselist_row = mysql_fetch_array($mouselist)) {
$mouselist_commonstrain = mysql_real_escape_string($mouselist_row['Common_Strain']);
echo "$mouselist_commonstrain.";
}
?>
I tried using mysql_real_escape_string.
Is there something in particular needed to display the <?
thanks
You want something like:
echo htmlspecialchars($mouselist_commonstrain);
(It needs to be HTML escaped.)
try this
$mouselist_commonstrain = stripslashes(htmlspecialchars($mouselist_row['Common_Strain']));
Your problem isn't escaping SQL but HTML. As answered in this question you can use htmlspecialchars function.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How remove extension from string (only real extension!)
Remove file extension on file upload
I am looking for ways to remove extensions but from what i found in google are really bad examples on how to do it.
$from = preg_replace('/\.[^.]+$/','',$from);
Something like this, any idea on how to do it?
Check out the basename function, which should do that for you. Note that it will also strip any folder names in the path.