0

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!

2 Answers 2

5

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));
Sign up to request clarification or add additional context in comments.

Comments

1

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));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.