php - jquery html() losing spaces -
I am testing a preg_replace function, and I process data from an Ajax function (I preg_replace, I have it in htmlentities ( ):
My test string is:
pr example123 ~! @ # $% ^ & Amp;;; () - + = {} | []:; & lt; & gt;? "..., '/ ... I am trying to ensure that not all those characters are being changed My function is:
$ String = preg_replace ('/ [^ a-zA-Z0-9 \ s + \ n \ r. \ / ~! @ # \ $% \ ^ & Amp; () \ + = {} \ [\] |: | << ']' -] / ',' ', $ String); I return from "echo" after going through htmlentities () to see both the data and the difference. (Data), I get it:
PR example 123 ~! @ # $% ^ & Amp;;; () - + = {} | [ ]:; & Lt; & gt;? "..., '/ ... public relations examples 123 ~! @ # $% ^ & Amp; ;; () - + = {} | []:; & Amp; Lt; & Amp; Gt; & Amp; Quot ;. .., & amp; # 039; / ... respectively. However, when I put any of these in $ ("# div"). Html (data) , I find: pr example 123 ~! @ # $% ^ & Amp; () - + = {} | []:; & Lt; & Gt; "... ..., '/ ... So many places are lost Why does the .html () function reduce the space? And how can I fix it Thank you
Remove "\ s +" from your regular expression and try again < / strike>
"I am trying to make sure that all those characters will not be changed." You mean it?
So I do a test like the one below :
$ string = "~! @ # $% ^ & Amp; () - + = {} | []:; & Lt; & Gt; "; // $ string = preg_replace ('/ [^ a-zA-Z0- 9] /', '', $ string); echo" ', $ string, "'"; Output
'~! @ # $% ^ & amp;; * () - + = {} | [] :; If you want to keep the full white space between "& lt;" and in the "& gt;" $ string, I can say that if you output to the same white space as the input There is no way to do it:
1 & gt; Use & lt; Pre & gt; tage
2 & gt; Use & amp; nbsp; to replace the white spot < / P>
Do you want this? If you want to Want to Get regular Why?
Comments
Post a Comment