Remove non breaking space: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
No edit summary
 
Line 9: Line 9:


== How to remove the non-breaking space In PHP ==
== How to remove the non-breaking space In PHP ==
Replace Non-breaking space with one whitespace using PHP: {{kbd | key=<nowiki>$result = str_replace("\xc2\xa0", ' ', $original_string);</nowiki>}}<ref>[https://stackoverflow.com/questions/40724543/how-to-replace-decoded-non-breakable-space-nbsp php - How to replace decoded Non-breakable space (nbsp) - Stack Overflow]</ref>
Replace Non-breaking space with one whitespace using PHP<ref>[https://stackoverflow.com/questions/40724543/how-to-replace-decoded-non-breakable-space-nbsp php - How to replace decoded Non-breakable space (nbsp) - Stack Overflow]</ref>
 
<pre>
$result = str_replace("\xc2\xa0", ' ', $original_string);
</pre>


== How to display the non-breaking space In PHP ==
== How to display the non-breaking space In PHP ==

Latest revision as of 13:56, 3 May 2022

How to display or remove non-breaking space

Definition[edit]

  1. Non-breaking space (不換行空格, nbsp;)

Sentence spacing

  1. Sentence spacing in digital media - Wikipedia e.g. &Nbsp; &Ensp; &Emsp;

How to remove the non-breaking space In PHP[edit]

Replace Non-breaking space with one whitespace using PHP[1]

$result = str_replace("\xc2\xa0", ' ', $original_string);

How to display the non-breaking space In PHP[edit]

$input = '12345678' . hex2bin('c2a0');
echo $input . PHP_EOL;
## Result of above script: '12345678 ' (one whitespace at the end)

echo bin2hex($input) . PHP_EOL;
## Result of above script: 3132333435363738c2a0

echo bin2hex('12345678') . PHP_EOL;
## Result of above script: 3132333435363738 (You mat notice the difference of script result is C2A0)

How to remove the non-breaking space In MySQL[edit]

SELECT REPLACE(`my_column`, UNHEX('C2A0'), '')
FROM `my_table`

How to display the non-breaking space In MySQL[edit]

SELECT CONCAT('12345678', UNHEX('C2A0'))
-- Result of above query: '12345678 ' (one whitespace at the end)

SELECT HEX(CONCAT('12345678', UNHEX('C2A0')))
-- Result of above query: 3132333435363738C2A0

SELECT HEX('12345678')
-- Result of above query: 3132333435363738 (You mat notice the difference of query result is C2A0)

SELECT LENGTH('12345678')
-- Result of above query: 8

SELECT LENGTH(CONCAT('12345678', UNHEX('C2A0')))
-- Result of above query: 10