Link to home
Start Free TrialLog in
Avatar of Torquil Beavis
Torquil BeavisFlag for Canada

asked on

How to assign string variable in php where string has both single and double quotes

Using PHP, I need to assign to a variable a long string that contains a number of single and double quotes which cause confusion when I surround the string with single or double quotes to contain it. I'm sure there must be a function to do this. However, search as I may, I cannot find one, nor contributors' solutions. These will be stored as files, not as DB records.

For example:
$string = 
"
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
line-height:normal;mso-outline-level:1'><b><span style='font-size:24.0pt;
font-family:"Times New Roman","serif";mso-fareast-font-family:"Times New Roman";
mso-font-kerning:18.0pt;mso-fareast-language:EN-CA'>Welcome Alpha Team!<o:p></o:p></span></b></p>
"

Open in new window


Clearly, the example can't work with Times New Roman contained by single or double quotes.

Is there a standard method to deal with this?
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Torquil Beavis

ASKER

Thanks Dave. Perfect!
You're welcome, glad to help.