quotes

PHP explode the string, but treat words in quotes as a single word

倾然丶 夕夏残阳落幕 提交于 2019-11-26 10:29:58
How can I explode the following string: Lorem ipsum "dolor sit amet" consectetur "adipiscing elit" dolor into array("Lorem", "ipsum", "dolor sit amet", "consectetur", "adipiscing elit", "dolor") So that the text in quotation is treated as a single word. Here's what I have for now: $mytext = "Lorem ipsum %22dolor sit amet%22 consectetur %22adipiscing elit%22 dolor" $noquotes = str_replace("%22", "", $mytext"); $newarray = explode(" ", $noquotes); but my code divides each word into an array. How do I make words inside quotation marks treated as one word? You could use a preg_match_all(...) :

Dealing with quotes in Windows batch scripts

Deadly 提交于 2019-11-26 10:25:25
问题 In a Windows batch file, when you do the following: set myvar=\"c:\\my music & videos\" the variable myvar is stored with the quotes included. Honestly I find that very stupid. The quotes are just to tell where the string begins and ends, not to be stored as part of the value itself. How can I prevent this from happening? Thanks. 回答1: set "myvar=c:\my music & videos" Notice the quotes start before myvar. It's actually that simple. Side note: myvar can't be echoed afterwards unless it's

Convert XmlDocument to String

青春壹個敷衍的年華 提交于 2019-11-26 10:09:14
问题 Here is how I\'m currently converting XMLDocument to String StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter); xmlDoc.WriteTo(xmlTextWriter); return stringWriter.ToString(); The problem with this method is that if I have \" ((quotes) which I have in attributes) it escapes them. For Instance: <Campaign name=\"ABC\"> </Campaign> Above is the expected XML. But it returns <Campaign name=\\\"ABC\\\"> </Campaign> I can do String.Replace \"

PHP static variables in double quotes

主宰稳场 提交于 2019-11-26 09:56:07
问题 How can I get PHP to evaluate a static variable in double quotes? I want to do something like this: log(\"self::$CLASS $METHOD entering\"); I\'ve tried all sorts of {} combos to get the variable value of self::$CLASS, but nothing has worked. I\'ve currently settled with string concatenation but it is a pain to type: log(self::$CLASS . \" $METHOD entering\"); 回答1: Sorry, you can't do that. It only works for simple expressions. See here. 回答2: Unfortunately there is no way how to do this yet.

Are single/double quotes allowed inside HTML attribute values?

北慕城南 提交于 2019-11-26 09:47:46
问题 I\'m trying to set attribute value that contains a single quote: var attr_value = \"It\'s not working\"; var html = \"<label my_attr=\'\" + attr_value + \"\'>Text</label>\"; $(\'body\').html(html); However, I get the following result: <label working=\"\" not=\"\" s=\"\" my_attr=\"It\">Text</label> How could I fix this ? Are double quotes allowed inside attribute values ? 回答1: Yes, both quotes are allowed in attribute values, but you must HTML-escape the quote you're using as an attribute

Remove quotes from a character vector in R

巧了我就是萌 提交于 2019-11-26 09:28:18
问题 Suppose you have a character vector: char <- c(\"one\", \"two\", \"three\") When you make reference to an index value, you get the following: > char[1] [1] \"one\" How can you strip off the quote marks from the return value to get the following? [1] one 回答1: as.name(char[1]) will work, although I'm not sure why you'd ever really want to do this -- the quotes won't get carried over in a paste for example: > paste("I am counting to", char[1], char[2], char[3]) [1] "I am counting to one two

How to use single quote inside an echo which is using single quote

ぐ巨炮叔叔 提交于 2019-11-26 09:09:56
问题 First of all, i have gone through the related questions.. haven\'t found any answer.. I m using this code to display a message echo \'Here goes your message with an apostrophe S like thi\'s \'; How can i make this work, as any quote inside this echo will break the statement... 回答1: Either escape the quote with a backslash, or use double quotes to designate the string. echo 'Here goes your message with an apostrophe S like thi\'s'; echo "Here goes your message with an apostrophe S like thi's";

How to escape double quotes in a title attribute

偶尔善良 提交于 2019-11-26 07:57:42
问题 I am trying to use a string that contains double quotes in the title attribute of an anchor. So far I tried these: <a href=\"..\" title=\"Some \\\"text\\\"\">Some text</a> <!-- The title looks like `Some \\` --!> and <a href=\"..\" title=\"Some "text"\">Some text</a> <!-- The title looks like `Some ` --!> Please note that using single quotes is not an option. 回答1: This variant - <a href=".." title="Some "text"">Some text</a> Is correct and it works as expected - you see normal quotes in

Regex to split a CSV

醉酒当歌 提交于 2019-11-26 07:56:44
I know this (or similar) has been asked many times but having tried out numerous possibilities I've not been able to find a a regex that works 100%. I've got a CSV file and I'm trying to split it into an array, but encountering two problems: quoted commas and empty elements. The CSV looks like: 123,2.99,AMO024,Title,"Description, more info",,123987564 The regex I've tried to use is: thisLine.split(/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/) The only problem is that in my output array the 5th element comes out as 123987564 and not an empty string. Description Instead of using a split, I think it

How to keep quotes in Bash arguments? [duplicate]

白昼怎懂夜的黑 提交于 2019-11-26 07:25:55
问题 This question already has answers here : Preserve Quotes in bash arguments (3 answers) Closed 5 days ago . I have a Bash script where I want to keep quotes in the arguments passed. Example: ./test.sh this is \"some test\" then I want to use those arguments, and re-use them, including quotes and quotes around the whole argument list. I tried using \\\"$@\\\" , but that removes the quotes inside the list. How do I accomplish this? 回答1: Just use single quotes around the string with the double