How can I put some values in input tag if the value contains single or double quotes? for example lets say I have this sentens: A du"mmy exam'ple If I put single quote around the value, "ple" will be disappeard, if double quote, "mmy exam'ple" will be disappeard. Is there a solution?
The problem is that I don't know what character may be in. I just used str_replace to replace dobule quote with " and it worked fine. Is there a function to do all the work without replacing problematic characters all together?
PHP offers the following solution: <?php $str = "A 'quote' is <b>bold</b>"; // Outputs: A 'quote' is <b>bold</b> echo htmlentities($str); // Outputs: A 'quote' is <b>bold</b> echo htmlentities($str, ENT_QUOTES); ?> Code (markup):
We know double quote has some extended functionality over single quote. Like: $var = 'hello world!'; echo "$var\n"; This will print: hello world!. This variable replacement is not available with single quote. My question is which is faster single quote or double quote? Which one is preferable to use?
Single quotes are faster. Double quotes will parse $variable that are found inside it. And $str ="Hello my name is ".$name is faster than $str ="Hello my name is $name"; though negligible in a sense but would matter when you have a very long string to parse