Page 1 of 1

Working with '\'

Posted: Thu Feb 12, 2004 2:54 pm
by pickle
Hi all.

Ok, here's my issue. I've got a challenge tracking system that, obviously, people can put challenges into. The problem I'm having is with keeping any ''' characters they put in. Since I'm storing this info in MySQL, I put in slashes before any database non-friendly characters, like ' and ". How do I go about removing the slashes that addcslashes puts in, but not the ones the user puts in. To date I've tried:

- calling htmlentities() on the incoming text before it's put in the database, to hopefully convert user entered ''' to their html code equivalent.
- calling stripcslashes() on the outgoing text which I had thought would only strip slashes that came before ' or ".

At this point, the only solution I can think of is to go through the incoming string character by character and change all occurrences of ''' to its html code equivalent.

Is there a cleaner more work intensive (for me :) ) solution?

Thanks.

Posted: Thu Feb 12, 2004 3:00 pm
by Cruzado_Mainfrm
why don't u try with addslashes() and stripslashes() without the 'c'?

Posted: Thu Feb 12, 2004 3:09 pm
by pickle
stripcslashes recognizes \n, \r, octal and hex representation, whereas stripslashes doesn't. The carriage return recognition is the primary reason why I don't use stripslashes. I have tested using stripslashes() as well, just to try, and it didn't change anything. Thanks though.

Posted: Thu Feb 12, 2004 7:20 pm
by McGruff

Posted: Tue Mar 02, 2004 10:57 am
by pickle
FYI: Here's the function I wrote - as far as I can tell it should do the same thing as addslashes, but alas addslashes does something funky, and not what I need.

Code: Select all

function custom_add_slashes($followup_info)
{
  $size = strlen($followup_info);
  for($x = 0;$x<$size;$x++)
  {
   $letters[] = substr($followup_info,$x,1);
  }
  $fixed_array;
  for($index = 0;$current_char = $letters[$index];$index++)
  {
   if($current_char == """ || $current_char == "'" || $current_char == "")
   {
    $fixed_array[] = "";
   }
   fixed_array[] = $current_char;
 }
 return(implode('',$fixed_array));
}