Heredocs parse error...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Heredocs parse error...

Post by raghavan20 »

When I run this code..I get this error..

Code: Select all

<pre>
<?php 

$input=<<<EOT
<body>
sample match 
<br />
<span style="text-decoration: underline">Special commands:</span>
<br />
<b>hi all</b> 
</body> 
EOT; 

echo preg_match_all("#<body>.*?<br />(.*?)<br /></body>#si", $input, $matches)."<br />"; 
print_r($matches); 

?> 
</pre>
Error...

Code: Select all

Parse error: parse error, unexpected $end in j:\apache\apache\htdocs\test\regex.php on line 18
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

make sure there's no whitespace before ending EOT; or after the semicolon.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

There were spaces and I deleted them but even then it does not work..

Code: Select all

<pre> 
<?php  

$input=<<<EOT 
<body> 
sample match  
<br /> 
<span style="text-decoration: underline">Special commands:</span> 
<br /> 
<b>hi all</b>  
</body>  
EOT;
echo preg_match_all("#<body>.*?<br />(.*?)<br /></body>#si", $input, $matches)."<br />";  
print_r($matches);  

?>  
</pre>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

there shouldn't be any whitespace after starting EOT as well
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

you are right Weirdan, there was a space after the initial EOT and now the problem is solved.

I am just curious what is the meaning of this error, T_SL. I am always not happy with the messages thrown by PHP on error.

Code: Select all

Parse error: parse error, unexpected T_SL in j:\apache\apache\htdocs\test\regex.php on line 13
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

raghavan20 wrote: I am just curious what is the meaning of this error, T_SL. I am always not happy with the messages thrown by PHP on error.

Code: Select all

Parse error: parse error, unexpected T_SL in j:\apache\apache\htdocs\test\regex.php on line 13
http://us2.php.net/manual/en/tokens.php
Post Reply