Jump to content

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING


jwhite68

Recommended Posts

I sometimes get the error - Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING .

when certain HTML strings are used.

 

e.g.

$html_string='<P class=MsoBodyText style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Arial><SPAN lang=EN-US>The house is a bungalow with 4 rooms: 3bedrooms,</SPAN><SPAN lang=EN-US style="mso-ansi-language: BG"> </SPAN><SPAN lang=EN-US>kitchen with oven</SPAN><SPAN lang=BG style="mso-ansi-language: BG">,</SPAN><SPAN lang=EN-US> extractor and hob</SPAN><SPAN lang=BG style="mso-ansi-language: BG">,</SPAN><SPAN lang=BG> </SPAN><SPAN lang=EN-US>3 bathrooms. It has a terrace and fully fenced wall. 2 air-conditioners are also available.</SPAN></FONT></FONT></P>\r\n<P class=MsoBodyText style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Arial><SPAN lang=EN-US>T</SPAN></FONT></FONT><FONT size=3><FONT face=Arial><SPAN lang=EN-US><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: ''Times New Roman''; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">he size of the living area is 155m2</SPAN></SPAN></SPAN></FONT></FONT></P>\r\n<P class=MsoBodyText style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face=Arial><SPAN lang=EN-US><SPAN lang=EN-US style="FONT-SIZE: 12pt; FONT-FAMILY: ''Times New Roman''; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"></SPAN></SPAN></SPAN></FONT></FONT><SPAN lang=EN-US><FONT face=Arial size=3>The size of the plot is 1,100 sq.m</FONT></SPAN></P>\r\n<P class=MsoBodyText style="MARGIN: 0in 0in 0pt"><SPAN lang=EN-US></SPAN><SPAN lang=EN-US style="FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">The price is <B>112,750 EUR / 77,759 GBP</B></SPAN> </P>';
$string=strip_tags($html_string);
echo $string;

 

Does anyone know whats causing this error.  I will be reading html text from a file, and simply want to apply strip_tags to remove the html code.  But it seems I cannot do this reliably.  The same code works fine for a smaller html_string.

Link to comment
Share on other sites

<?php

$html_string="<P class=MsoBodyText style='MARGIN: 0in 0in 0pt'><FONT size=3><FONT face=Arial><SPAN lang=EN-US>The house is a bungalow with 4 rooms: 3bedrooms,</SPAN><SPAN lang=EN-US style='mso-ansi-language: BG'> </SPAN><SPAN lang=EN-US>kitchen with oven</SPAN><SPAN lang=BG style='mso-ansi-language: BG'>,</SPAN><SPAN lang=EN-US> extractor and hob</SPAN><SPAN lang=BG style='mso-ansi-language: BG'>,</SPAN><SPAN lang=BG> </SPAN><SPAN lang=EN-US>3 bathrooms. It has a terrace and fully fenced wall. 2 air-conditioners are also available.</SPAN></FONT></FONT></P>\r\n<P class=MsoBodyText style='MARGIN: 0in 0in 0pt'><FONT size=3><FONT face=Arial><SPAN lang=EN-US>T</SPAN></FONT></FONT><FONT size=3><FONT face=Arial><SPAN lang=EN-US><SPAN lang=EN-US style='FONT-SIZE: 12pt; FONT-FAMILY: ''Times New Roman''; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA'><SPAN lang=EN-US style='FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA'>he size of the living area is 155m2</SPAN></SPAN></SPAN></FONT></FONT></P>\r\n<P class=MsoBodyText style='MARGIN: 0in 0in 0pt'><FONT size=3><FONT face=Arial><SPAN lang=EN-US><SPAN lang=EN-US style='FONT-SIZE: 12pt; FONT-FAMILY: ''Times New Roman''; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA'><SPAN lang=EN-US style='FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA'></SPAN></SPAN></SPAN></FONT></FONT><SPAN lang=EN-US><FONT face=Arial size=3>The size of the plot is 1,100 sq.m</FONT></SPAN></P>\r\n<P class=MsoBodyText style='MARGIN: 0in 0in 0pt'><SPAN lang=EN-US></SPAN><SPAN lang=EN-US style='FONT-SIZE: 11pt; FONT-FAMILY: Arial; mso-bidi-font-size: 12.0pt; mso-ansi-language: EN-US; mso-fareast-font-family: ''Times New Roman''; mso-fareast-language: EN-US; mso-bidi-language: AR-SA'>The price is <B>112,750 EUR / 77,759 GBP</B></SPAN> </P>";
$string=strip_tags($html_string);
echo $string;

?>

 

Only use one type of quote, either single or double, throughout your entire string, unless you are escaping them.

Link to comment
Share on other sites

this bit - FONT-FAMILY: ''Times New Roman''

 

note you have TWO single quotes! either escape the one set of quotes like so

 

FONT-FAMILY: \'Times New Roman\'

 

OR use doube quotes for that like so

 

FONT-FAMILY: "Times New Roman"

 

You could help your self and remove all those pointless font tags and style it properly!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.