jbille Posted October 18, 2006 Share Posted October 18, 2006 I was wondering how I could replace a period(.) and a dash(-) when passing them through a form to mysql. Link to comment https://forums.phpfreaks.com/topic/24381-replacing-special-characters-in-php-form/ Share on other sites More sharing options...
Caesar Posted October 18, 2006 Share Posted October 18, 2006 [code]<?phpstr_replace(".","",$string);?>[/code] Link to comment https://forums.phpfreaks.com/topic/24381-replacing-special-characters-in-php-form/#findComment-110902 Share on other sites More sharing options...
jbille Posted October 18, 2006 Author Share Posted October 18, 2006 What character besides "" can I replace it with so I can return it back to original form when outputting it. Link to comment https://forums.phpfreaks.com/topic/24381-replacing-special-characters-in-php-form/#findComment-110924 Share on other sites More sharing options...
sanfly Posted October 18, 2006 Share Posted October 18, 2006 Are you trying to replace them because your getting errors when you pass data containing those characters? if so, check out addslashes() and stripslashes() in the [url=http://www.php.net]PHP MANUAL[/url] Link to comment https://forums.phpfreaks.com/topic/24381-replacing-special-characters-in-php-form/#findComment-110926 Share on other sites More sharing options...
redarrow Posted October 18, 2006 Share Posted October 18, 2006 Use this on all varables that select from the database.$example=mysql_real_escape_string($example));[code]<?php// Connect$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') OR die(mysql_error());// Query$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'", mysql_real_escape_string($user), mysql_real_escape_string($password));?> [/code] Link to comment https://forums.phpfreaks.com/topic/24381-replacing-special-characters-in-php-form/#findComment-110928 Share on other sites More sharing options...
slancasterfreak Posted October 18, 2006 Share Posted October 18, 2006 you can replace it with anything unique like [code]<?php$stringtostore=str_replace(".","perxx",$string);?>[/code]and then when you get it back out, replace it back with-[code]<?php$gotstring=str_replace("perxx",".",$storedstring);?>[/code] Link to comment https://forums.phpfreaks.com/topic/24381-replacing-special-characters-in-php-form/#findComment-110932 Share on other sites More sharing options...
jbille Posted October 19, 2006 Author Share Posted October 19, 2006 I am trying to let the user enter 123-456 in the form, and I want to load that number in a database. However when I try this it just loads 123 in mysql and it stops at the -. The same goes for 2.50, this puts 2 in the database. And when I try to use $number=str_replace("-","000000", $number); it puts a false number into mysql. I am using 000000 because $number is an INT(30). Link to comment https://forums.phpfreaks.com/topic/24381-replacing-special-characters-in-php-form/#findComment-110948 Share on other sites More sharing options...
redarrow Posted October 19, 2006 Share Posted October 19, 2006 use varchar(30) then try ok. Link to comment https://forums.phpfreaks.com/topic/24381-replacing-special-characters-in-php-form/#findComment-110952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.