Passing a argument with '!' with bash [duplicate] - php

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.

Related

How would I take a string, find a certain character, add a character, and continue until end of string? [duplicate]

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

Read ini file in PHP, not parse [duplicate]

This question already has answers here:
PHP: Escape illegal chars in .ini-files
(2 answers)
Closed 1 year ago.
When using parse_ini_file, it will attempt to read and understand the ini file. I'm looking for a solution that will read the file, place it into arrays much like parse_ini_file does, however I don't want it to get to the special characters in my ini file and spit an error that it can't parse them. Could anyone point me in the right direction?
ini file for reference:
[IMPORT]
email=email#thisisanemail.com
location=
Description=Order Form
name=*.xls*
matrixfile=
matrix_field=
matrix_disc_type_column=
matrix_disc_percentage_column=
fixed=XLS
separator=|
RowTerminator=
headerrows=13
footerrows=0
maxexcelcolumns=7
If I parse this, it gets stuck on the seperator "|" but I need that there.
If you use parse_ini_file with the scanner_mode parameter to specify INI_SCANNER_RAW, then option values will not be parsed (see
https://www.php.net/manual/en/function.parse-ini-file.php).

Find & Replace MySQL [duplicate]

This question already has answers here:
MySQL string replace
(6 answers)
Closed 8 years ago.
I'd like to perform a find & replace in MySQL in GoDaddy's phpMyAdmin tool.
My table is called "wcswcd_posts", and I would like to find a URL, like:
http://wordpress.woodswcd.com/wordpress/wp-content/uploads/2013/11/drill.jpg
And replace it with:
/wordpress2/wp-content/uploads/2013/11/drill.jpg
Just not sure of what the syntax would be.
Thank you.
You are going to need to use the UPDATE statement & the REPLACE function
to change it try:
UPDATE wcswcd_posts SET url = REPLACE(url,'http://wordpress.woodswcd.com','')
REPLACE is a string function that replaces every occurrence of the 2nd string in the 1st string with the 3rd one.
By setting the 3rd argument in the REPLACE function to nothing, you will get rid of any occurence of http://wordpress.wordswcd.com leaving /wordpress/wp-content/uploads/2013/11/drill.jpg
This link should get you started.
Just replace http://wordpress.woodswcd.com/wordpress/ with http://wordpress.woodswcd.com/wordpress2/

How do I stripslashes from something I include in PHP? [duplicate]

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

Bug encountered while Executing .exe file from a Php script [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Why is PHP not replacing the variable in string?
I have been trying to execute this line echo exec('hi.exe $file',$results,$status); from Php. where the value assigned to $file is the filename hi.txt (i.e. $file = hi.txt).
But each time i try to run my code with the same line, its showing error as $file file not found where as if i run the same hi.exe hi.txt in a command prompt its working.
And also if i try to run the same line with the filename instead of a variable from php i.e.exec('hi.exe hi.txt',$results,$status), the browser keeps executing for long time without giving the output.
Please someone tell me where i am going wrong!
You are using single quotes, instead of double quotes. Change echo exec('hi.exe $file',$results,$status); to:
echo exec("hi.exe $file",$results,$status);
or use a dot, like this:
echo exec('hi.exe '.$file,$results,$status);
In PHP, using single quotes won't turn $file into hi.txt; it just stays as the literal string, "$file". Use double quotes or dot concatenation to actually expand $file into hi.txt
Single quotes don't expand variables. You probably mean:
echo exec("hi.exe $file",$results,$status);

Categories