简体   繁体   中英

Where does amp; come from?

in javascript, I have:

var stop_symbols = $("#words_stop_symbols span").html().split('');
console.dir(stop_symbols);

html:

 <span>*/&amp;^\</span>

When php is simply:

<span>Array
(
    [0] => *
    [1] => /
    [2] => &amp;
    [3] => ^
    [4] => \
)
</span>

But in DB I only have character &

So where does this amp come from?

My final aim is to use this letters and get charCode for them using str.charCodeAt(0);

"Ampersand" is the name for the character "&" in English. &amp; is the HTML code for "&".

Use html_entity_decode() .

<?php
$orig = "I'll \"walk\" the <b>dog</b> now";

$a = htmlentities($orig);

$b = html_entity_decode($a);

echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now

echo $b; // I'll "walk" the <b>dog</b> now
?>

Source: http://www.php.net/manual/en/function.html-entity-decode.php

I'm answering myself. Changing:

html() to text() fixed it.

You just have to change

var stop_symbols = $("#words_stop_symbols span").html().split('');

in

var stop_symbols = $("#words_stop_symbols span").text().split('');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM