Page 1 of 1
Help with removing &'s
Posted: Tue Mar 27, 2007 4:57 pm
by 303tech
I'm having problems when the string has &'s in it, as well as 's. I was able to remove the 's. But i get a return value of 0 when trying to do the same thing with &'s. If i take out the part where I'm trying to remove &, the value of $replace is OK.
Code: Select all
//PARSE INI FILE.
$ini = parse_ini_file('config.ini');
//REMOVE APOSTROPHES FROM NAME.
$and="&";
$ini1=$ini['UNITNAME'];
$unitname=str_replace($and,"AND",$ini1);
echo $unitname;
$replace=str_replace("'","",$unitname);
echo $replace;
Also, is there a way that I can put chars like this in db fields?
Posted: Tue Mar 27, 2007 5:55 pm
by impulse()
Code: Select all
$and = "&";
$speech = "'";
$ini['UNITNAME'] = "AND & SPEECH '";
$ini1 = $ini['UNITNAME'];
$unitname = str_replace($and,"AND",$ini1);
$unitname = str_replace($speech, "APOSTROPHY", $unitname);
echo $unitname;
That works fine for me.
Posted: Tue Mar 27, 2007 6:02 pm
by aaronhall
Have you checked that $ini['UNITNAME'] was set to begin with?
Posted: Tue Mar 27, 2007 6:15 pm
by 303tech
in the ini...i think its having a problem because it reads .
UNITNAME=Joe's Pizza & Pasta
but returns a 0 still.
I take off the part where im trying to take out the &, and it returns fine with just the apostrophe taken out.
Re: Help with removing &'s
Posted: Wed Mar 28, 2007 1:03 am
by Kieran Huggins
303tech wrote:I'm having problems...
Can you be more specific?
Posted: Wed Mar 28, 2007 1:16 am
by s.dot
Code: Select all
str_replace(array("'", "&"), '', $var);
that, or a modification of it, should work
Posted: Wed Mar 28, 2007 1:18 am
by s.dot
Also, is there a way that I can put chars like this in db fields?
mysql_real_escape_string()
htmlentities()
Posted: Wed Mar 28, 2007 6:38 pm
by 303tech
PHP PARSE Actually returns 0 when there is a & in the string. There is nothing to parse. *scratches head*