Hi all. Im very new to PHP so heres my q
I have an array that has multiple different sentences in various indexes. The sentences contain (')apostrophes and
(")double quotes.
I want my array at whatever index to echo the sentece-
The boat's anchor is "heavy".
If I do this-
...it cuts the sentence off at the (')apostrophe. If I do this-
...it cuts the sentence off at the (')apostrophe. If I remove the (')apostrophe both senteces echo correctly with the double quotes visible.
I thaught this was true that
Using double quotes in a string enclosed with single quotes requires no escaping and vica versa.
Using a double quotes in a string enclosed in double quotes does require escaping.
I've tried using the str_replace function to replace the apostrophe with HTML character code '
...and it still cuts off at (')apostrophes.
The only option that works so far is using html character codes in the sentece itself-
...But this makes readability more difficult.
Is there any other ways you can help me with solving my problem with the single quotes / (')apostrophes not displaying when the sentence is echo'd?
I have an array that has multiple different sentences in various indexes. The sentences contain (')apostrophes and
(")double quotes.
I want my array at whatever index to echo the sentece-
The boat's anchor is "heavy".
If I do this-
Code:
myArr[0] = "The boat's anchor is \"heavy\"."; echo myArr[0];
Code:
myArr[0] = 'The boat\'s anchor is "heavy".'; echo myArr[0];
I thaught this was true that
Using double quotes in a string enclosed with single quotes requires no escaping and vica versa.
Using a double quotes in a string enclosed in double quotes does require escaping.
I've tried using the str_replace function to replace the apostrophe with HTML character code '
Code:
$str = str_replace("'", "'", myArr[0]); echo $str;
The only option that works so far is using html character codes in the sentece itself-
Code:
myArr[0] = "The boat's anchor is \"heavy\"."; echo myArr[0];
Is there any other ways you can help me with solving my problem with the single quotes / (')apostrophes not displaying when the sentence is echo'd?
Comment