quotes

Escaping characters by doubling them in PHP

我与影子孤独终老i 提交于 2019-12-13 10:21:16
问题 Is there a simple way to escape/unescape an arbitrary character in PHP by doubling it, for example: in ANSI SQL, "you can ""escape"" this way" in printf(), you can express a %% this way Escaping is quite easy with str_replace() , but reversing the process to unescape the string is not that easy, so does anyone know of a pair of functions, or a library to do this? The idea is that I need to serialize an array this way: array('a','b', '~','c') => 'a~b~~~~c' The individual strings cannot be

How to make variables work in Single Quotes properly?

狂风中的少年 提交于 2019-12-13 03:42:24
问题 I want those variables to be filled with their values, but in config.php file its writing the variable name itself, I want like $host convert to 'localhost' with single quotes in the config.php file. $handle = fopen('../config.php', 'w'); fwrite($handle, ' <?php $connection = mysql_connect({$host}, {$user}, {$pass}); ?> '); fclose($handle); 回答1: If you use variables within single quotes, they will be represented as strings instead of variables. You can also do it like this: // Get from $

Separate fields by comma and quotes in Python?

拜拜、爱过 提交于 2019-12-13 02:13:43
问题 I'm trying to separate this csv file into a 2D list. The problem with my code currently is that it cuts off a few fields on lines with quotes in the data. There are quotes there to signify that the comma within is not part of the comma separation of fields and is actually part of the field. I posted the code, example data, and example output. You can see how the first output line skips a few fields compared to the rest because of the quotes. What do I need to do with the regular expression

Python split string by spaces except when in quotes, but keep the quotes

左心房为你撑大大i 提交于 2019-12-12 23:03:35
问题 Am wanting to split the following string: Quantity [*,'EXTRA 05',*] With the desired results being: ["Quantity", "[*,'EXTRA 05',*]"] The closest I have found is using shlex.split, however this removes the internal quotes giving the following result: ['Quantity', '[*,EXTRA 05,*]'] Any suggestions would be greatly appreciated. EDIT: Will also require multiple splits such as: "Quantity [*,'EXTRA 05',*] [*,'EXTRA 09',*]" To: ["Quantity", "[*,'EXTRA 05',*]", "[*,'EXTRA 09',*]"] 回答1: To treat

Regex Question - One or more spaces outside of a quote enclosed block of text

让人想犯罪 __ 提交于 2019-12-12 18:25:50
问题 I want to be replace any occurrence of more than one space with a single space, but take no action in text between quotes. Is there any way of doing this with a Java regex? If so, can you please attempt it or give me a hint? 回答1: Here's another approach, that uses a lookahead to determine that all quotation marks after the current position come in matched pairs. text = text.replaceAll(" ++(?=(?:[^\"]*+\"[^\"]*+\")*+[^\"]*+$)", " "); If needed, the lookahead can be adapted to handle escaped

Echoing javascript from PHP

≯℡__Kan透↙ 提交于 2019-12-12 17:09:44
问题 I am trying to echo some google analytics javascript code from PHP so it can be conditionally read based on specific scenarios. I'm having difficulty wrapping my head around the quoting since the code contains /* */ characters. I'm looking for some direction in assigning this type of text to a php variable. Thanks $sJS .='<script type="text/javascript">'; $sJS .='/* <![CDATA[ */"'; $sJS .='var google_conversion_language = "en";'; $sJS .='var google_conversion_format = "2";'; $sJS .='var

Shell.Run with arguments

一笑奈何 提交于 2019-12-12 16:20:48
问题 I'm trying to run a program (with argument /config ) using Shell.Run from VBS. However I'm having an exit code = 87 (cannot find the file specified). 1st piece of code I've tried: strCommand = """c:\Program Files\Test\launch.exe""" & " /config:C:\sample.xml" intExit = objShell.Run(strCommand, 0, True) 2nd piece of code: Dim FileExe, Argum FileExe = "%ProgramFiles%\Test\launch.exe" Argum = "/config:C:\sample.xml" RunMe FileExe, Argum Function RunMe(FileExe, Argum) Dim Titre, ws, Command, Exec

When to use single quotes in an SQL statement?

久未见 提交于 2019-12-12 13:14:09
问题 I know that I should use it when I deal with data of TEXT type (and I guess the ones that fall back to TEXT), but is it the only case? Example: UPDATE names SET name='Mike' WHERE id=3 I'm writing an SQL query auto generation in C++, so I want to make sure I don't miss cases, when I have to add quotes. 回答1: Single quotes ( ' ) denote textual data, as you noted (e.g., 'Mike' in your example). Numeric data (e.g., 3 in your example), object (table, column, etc) names and syntactic elements (e.g.,

MySQL choking on curly (smart) quotes

拈花ヽ惹草 提交于 2019-12-12 09:37:15
问题 I'm inserting some data into a database from a form. I'm using addslashes to escape the text (have also tried mysql_real_escape_string with the same result). Regular quotes are escaped, but some other quotes are not. For example, the string: Homer's blood becomes the secret ingredient in Moe’s new beer. is converted to: Homer\'s blood becomes the secret ingredient in Moe’s new beer. I didn't think the curly quote would matter unescaped, but only this text is inserted into the database: Homer

Why backslashes are being added to all the $_GET, $_POST automatically?

耗尽温柔 提交于 2019-12-12 05:49:49
问题 I have a vps with cPanel/Whm/CentOS 5.5 and the problem is that all parameters sent to my server are being addslashed , I've checked out the PHP configuration and i found out that all the magic quotes are turned off and i don't know what causes this. My code is so clean and i know every bit of it and i don't have any addslashes() or some sort of these functions. i only want to receive the parameters as they are. URL: test.php?text=blah" ' " 'blah <?php echo $_GET["text"]; // Output blah\" \'