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.

<?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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.