1

When I fetch data from my database to my php. I get and when I check it's source it looks something like this:

  <li class="ui-state-default"><input type="checkbox" id="check1" class="chk" name="countryname[]" value="AF 
" > AFGHANISTAN`

in the value field you can see there is space after AF. Now the problem which occurs here is that these space are not in database and i want to skip these spaces and this is not even in my php code. Well they could be in my database but I want to skip them or delete them from database.

Here is my code <ul id="sortable"> <? while($row = mysql_fetch_array($result)) { ?> <li class="ui-state-default"><input type="checkbox" id="check1" class="chk" name="countryname[]" value="<?echo urldecode($row['Code']);?>" <? $reflex = mysql_query("select distinct * from geocity where isAllowed='1' AND country='" . $row['Code'] . "'"); $count = mysql_num_rows($reflex); if ($count == 0){echo '';}else{echo 'checked';} ?>>&nbsp;<? echo $row['CountryName']; ?> </li> <? }; ?>

4
  • 1
    so go look at the code that generates this html. if the spaces/breaks aren't in the db, then php is the obvious next stop for checking. Commented Apr 9, 2013 at 19:07
  • we'd need to see your code but maybe you have something like echo "$country['code'] "; in your php. with a space, i mean. Commented Apr 9, 2013 at 19:13
  • Do you have any php-code? Commented Apr 9, 2013 at 19:23
  • @HAB - Please edit your question and put your code there instead :-) Commented Apr 9, 2013 at 19:31

3 Answers 3

1

You can use TRIM(BOTH ' \r\n\t' FROM [the column name]) when you select your data to remove bogus endings and beginnings.

In PHP you can just use trim(), as it already also removes tabs, newlines and such.

If you clean up those fields in the database you also should look for breaks inside the strings and kill them with REPLACE :)

Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried

trim($value)

Also some code would be helpful

3 Comments

TRIM() only removes spaces and only at the very beginning or ending
@nicogawenda - wasn't that the point? to remove space at the end?
@bestprogrammerintheworld: and breaks;)
0

You could use regular expressions to find the content between the double quotes then remove the spaces from the contents? I would suggest trim as Jim did, but that is for white space at the beginning and end of a string.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.