Replace &Nbsp; Characters That Are Hidden in Text

replace   characters that are hidden in text

This solution will work, I tested it:

$string = htmlentities($content, null, 'utf-8');
$content = str_replace(" ", "", $string);
$content = html_entity_decode($content);

How to remove   from a UTF-8 string?

This gets tricky, its not as straight forward as replacing normal string.

Try this.

 str_replace("\xc2\xa0",' ',$str); 

or this, the above should work:

$nbsp = html_entity_decode(" ");
$s = html_entity_decode("[ ]");
$s = str_replace($nbsp, " ", $s);
echo $s;

@ref: https://moovwebconfluence.atlassian.net/wiki/pages/viewpage.action?pageId=1081435

Replace   with a blank or empty string PHP

$text_description="       Hello world! lorel ipsum";
$text_description = str_replace(' ', ' ', $text_description);
echo $text_description;

Output:

Hello world! lorel ipsum

What is the best invisible character can I use to replace  ?

You could use Unicode code point U+00A0 (non-breaking space), which is what the entity   represents. How this should be encoded in your document depends on the character set in use.

Remove ' ' - still trying

You have   in your code instead of  

$('p').each(function(){
$(this).html($(this).html().replace(/ /gi,''));
});

http://jsfiddle.net/genesis/hbvjQ/76/

how to remove   by javascript

Without replacing the malformed   you can replace the innerHTML of each node

var options = document.getElementsByTagName('option')
for (index = 0; index < options.length; ++index) {
options[index].innerHTML = options[index].innerHTML.replace(/\ /g, '');
}

working example: https://jsfiddle.net/2h6hqc0g/

How to remove   from inside tags, inside a string

Replace repetitions of spaces and/or   with a single  :

preg_replace('/(?: | ){2,}/', ' ', $string);

If you want to convert all   to spaces, and then collapse the spaces then:

preg_replace('/ {2,}/', ' ', str_replace(' ', ' ', $string));

Note that this is not going to remove single spaces from after the opening tag, or before the closing tag. For something like that you're getting into some pretty nasty territory with regular expressions and you'll want to parse the document using DOM or XML instead.

However, leading and trailing whitespace is generally insignificant in HTML, so this should get you where you're going.

Is it possible to remove ' ' using JQuery..?

No, you would do something along these lines:

$("td").html(function (i, html) {
return html.replace(/ /g, '');
});


Related Topics



Leave a reply



Submit