Pesky Quotes, What should i do with them?
Tuesday, October 23rd, 2007 at 10:05 amWell about an hour ago i lost my thumb drives which hold all my basic functions i use on a day to day basis. As any Geek will tell you this sort of thing almost certianly means the end of the world, but i will go on. Without them im at a huge loss, so as i try to rebuild my library of functions ill post some of them. Note: Most of the functions are all php.
Ever try to create a back-end for a website, or simple just building a form, and can’t seem to get those damn quotes to show in the textbox? Well my co-worker just asked me about this and is pretty frustrated. The simple solution is to create a basic function that uses a string replace to put in the 7-bit ASCII value instead of the character.
Example 1 - Quotes in a text box:
1 2 3 4 5 6 7 8 9 10 | <?PHP
function code_for_ascii($data) {
$temp = str_replace("'", ''', $data); //Single Quote
$temp = str_replace('"', '"', $temp); //Double Quote
return $temp;
}
$test_variable = '"jason"\'';
?>
<input type="text" name="test" value="<?PHP echo code_for_ascii($test_variable); ?>"> |
This functions cool and you may have tried it just now. If you did you’ll see that when you submit the form the returned response is
\”jason\”\’
kinda wierd but it will escape the characters for you. Now say you want to put that request back into a textbox you’ll need to do it like so.
1 2 3 4 | <?PHP
$variable_1 = code_for_ascii(stripslashes($_REQUEST['test']));
?>
<input type="text" name="test" value="<?PHP echo $variable_1; ?>"> |
Author: Jason Rogers
Tags: Jason Rogers, MYSQL, PHP, quotes, textbox
Welcome to Neurotic Geeks a personal blog about a flourishing programmer (Jason Rogers) in the web industry. You'll experience many a wonder while visiting. Oh, and i love guitar.




