Jump to content

Recommended Posts

Posted

Hi, can anyone please give me complete working code for here document in PHP? Please do not give extracts of the example like

 

<?php

echo <<

 

Hi, I want an example of php here document.

Not the extracts of php code, rather complete code.

I mean starting with and ending with .

Please put code only if you were able to interpret/ compile the code succussfully.

 

END;

 

?>

 

If you could provide the solution, I am thankful to you. Otherwise too thankful.... Just kidding

Posted
I read all these example. I copied the example and embedded in html tags. But when I try to compile them parsing error occurs. Did your code interpret well? If yes please give me html embedded code.

 

Post the code you are working with/what error you get, and I can take a look and see what the issues is.

Posted

<?php

$name = "Joe Smith";

$occupation = "Programmer";

echo <<

 

This is a heredoc section.

For more information talk to $name, your local $occupation.

 

Thanks!

 

EOF;

 

$toprint = <<

 

Hey $name! You can actually assign the heredoc section to a variable!

 

EOF;

echo strtolower($toprint);

 

 

?>

  • 2 weeks later...
Posted

I was trying to find out where the actual problem was and I found very strange reason. If I try to add space before closing here document identifier END; parse error happens. Otherwise the code runs well. I did not find any explanation for that as PHP supports any no space to be included.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...