0

When I copy a domain name from Google Maps and then paste it into a form I built, it enters it into a MySQL database with ‎ appended at the end of the domain name.

Any idea how I could strip that ‎ off of the domain name?

The relevant code is below

<div class="friend5title"><label for="url">Website:</label></div> 
    <div class="friend5field"><input name="website" type="text" id="website" maxlength="150"></div>



$website = mysql_real_escape_string($website);

mysql_query("INSERT INTO submission VALUES ('$website')");
John
  • 4,820
  • 21
  • 62
  • 92

2 Answers2

1

It is a control character ( http://en.wikipedia.org/wiki/Left-to-right_mark ).

Ignore all of my previous answer I just realized (since I wrote quickly) it isn't in unicode it is actually in a HTML entity format so you need to strip that HTML entity out:

preg_replace('/(&#8206;)/', '', $string);

An alternative is to actually purify your string and purge it of all HTML entities since it shouldn't really have any in it. Normally there could be special characters like &amp; but these should not exist in a URL taken from an input field I reckon.

Here is a question about removing HTML entities with a solid answer: How to remove html special chars?

As to why it is happening: it is possible that someone has a foreign browser which artifically makes the text in inputs go a certain way but in turn by adding this html entity.

pableiros
  • 14,932
  • 12
  • 99
  • 105
Sammaye
  • 43,242
  • 7
  • 104
  • 146
0

On pasting in the input field you did copy a left-to-right character, with unicode number 8206. As the browser evidently did have a form not in some unicode character set (like UTF-8), it sent to the server that character as numeric entity &#8206;. The server has to decode these, or the form (and page) has to be changed to accept UTF-8.

In the case of your LTR-character, it seems superfluous. You could add an onchange=... to remove characters < 0 and > 127 for the URL. They still are characters, so that is easily done.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138