Reputation: 703
I am an ASP programmer trying to write PHP, so my apologies if this is really basic. I have a variable $fname and I am trying to setup an array as follows:
$data=array('x_First_Name' => '" . str_replace("'" ,"\'", $fname) . "');
But, I get an error: unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')'
Something simple in my syntax that needs to be adjusted? Thanks!
Upvotes: 0
Views: 38
Reputation: 4680
If you have only a variable or a function, you don't need to add quotes. And to 'break' the quotes for a function or a variable, you need to use the same quotes.
$data=array('x_First_Name' => str_replace("'" ,"\'", $fname));
Upvotes: 1
Reputation: 29168
You don't need to quote the value:
$data=array('x_First_Name' => str_replace("'" ,"\'", $fname) );
You might also find PHP's addslashes()
helpful:
$data=array('x_First_Name' => addslashes($fname));
Upvotes: 5