xpath - PHP DOMXPath works with double quotes fails with single quotes -
I have written a small script that can be used by PHP's But as soon as I keep changing the quote (which should not make any difference): or How is this possible and how can I remove it? Live example here: The style of citations make a difference Because - in which you are using non-breaking space for When they are attached to single-quotes A little extra syntax highlighting can help show this show, escape sequence in orange: If you already have a string, then the scenes that will be running in it will be in the form of literal characters , And no way to correct it * , you are in a somber mood of changing yourself. This Output: (* actually In, you should decide it on the source.) DOMXPath class information from the Web site Removes.
I & lt; Div class = "sku" /> I query for and execute a
substring-before result on the result include text, non-breaking spaces, a line break, and more text.
So what I am trying to do is & amp; Nbsp; & Amp; Nbsp; \ R \ n . When I use the following query it works fine:
$ query = "substring-before (// div [@ class = 'sku'], '\ xC2 \ xA0 \ XC2 \ xA0 \ r \ n ') ";
$ query = 'substring-before (// div [@ Class = "sku"], "\ xC2 \ xA0 \ xC2 \ xA0 \ r \ n") ';
$ query = 'substring-before (// div [@class = \' sku \ '], \' \ xC2 \ xA0 \ XC2 \ xA0 \ r \ n \ ')';
\ xC2 \ xA0 , carriage return
\ r , and newline
\ n .
'\ xC2 \ xA0 \ r \ n' , as in your other two questions, PHP treats them as those letters. Does - backslash, x, c, 2 ... etc
preg_replace_cal will take care of sorted sequences in your example, and is trivial to expand in the remaining part supported by double quotes:
// Good known. $ Query1 = "substring- first (// div [@ class = 'sku'], '\ xC2 \ xA0 \ xC2 \ xA0 \ r \ n')"; / Known bad $ Query2 = 'substring- first (// div [@class = \' sku \ '], \' \ xC2 \ xA0 \ xC2 \ xA0 \ r \ n \ ');'; $ Query2 = preg_replace_callback ('/ \\\\ (?: [RN] | (?: X [0- 9A-FA-F] {1,2}) /', function ($ matches) {switch ( Substant ($ matches [0], 0, 2)) {case '\ r': return "\ r"; case '\ n': return "\ n"; case '\ x': return hex2bin (substr ($ Matches [0], 2));}}, $ query2); Var_dump ($ query1 === $ query2); // now equals?
bool (true)
Comments
Post a Comment