Greetings, June 26th 2013

Presently I am attempting to assign a variable to 12-15 lines of html and even after escaping the quotes, double quotes I have yet been successful. I have attempted "heredocs" and the attempt was in vain after I as well went through the block and attempted to provide quotes, doubles where I thought they may be needed. each of the described tests were with new blocks of the html. The block of HTML is part of a large file and is integrated with forms and bringing in the HTML through file etc isn't feasible. Any ideas?

Appreciatively,
Ted

    a [man]heredoc[/man] is the easiest way to do this. Are you sure you got it right?

    $myHTML = <<< HEREDOC
    <!doctype html>
    <html lang="en">
      <head>
        <meta charset="UTF-8">
        <title>Some Random HTML Page</title>
      </head>
      <body>
        <h1>Some Random HTML</h1>
        <p>This should work just fine.
      </body>
    </html>
    HEREDOC
    ;

      Your example is pretty much what I did with the exception that there were and astronomical amount of quotes, double quotes within my html block? Your help is appreciated :-)

        tedteeter wrote:
        Your example is pretty much what I did with the exception that there were and astronomical amount of quotes, double quotes within my html block? Your help is appreciated :-) 

        Was that a question? Because it looks like a lot of gibberish.

          Usual gotcha with heredoc is having spaces/tabs before the closing string delimiter: it must be the first and only thing on that line.

            tedteeter;11030583 wrote:

            Your example is pretty much what I did with the exception that there were and astronomical amount of quotes, double quotes within my html block? Your help is appreciated :-)

            Quotes (of any kind) are a non-issue: they don't have any impact on the heredoc. The only thing that will close the heredoc is the closing identifier (which, as NogDog says, needs to be the "first" and "only" thing on its line).

              Well based upon all I have read that has been allowed by you helpful wonderful people is that perhaps "the html block may have been to large?"....I attempted the "Heredoc" several times in various manners while that statement isn't very confusing that must be the only explanation while I used it as the first php encountered in the page before several form issets....Again your help is greatly appreciated :-)

                Can you show us the exact code you tried as well as the exact error message(s) it produces?

                The only time the text would be "to[sic] large" would be if you managed to consume all of PHP's memory_limit in the variable assignment. (This is rather unlikely.)

                  bradgrafelman wrote:

                  The only time the text would be "to[sic] large" would be if you managed to consume all of PHP's memory_limit in the variable assignment. (This is rather unlikely.)

                  I was going to add "and in that case the error would have been different", but then I realised I'm not clear just what the error actually is.

                    Okay!...I have been attempting to get that large block of HTML to pass with "heredoc" and it won't even pass a character. However, I did compose a few lines of html and utilized some php echo values i.e <input type="text" name="test" value="<?php echo "test"; ?>"> and that does pass fine, again, however the php values retain the entire php statement in the input value field as <?php echo "test"; ?> as if you were offline. Is it possible to pass the values as such or have I missed something?..Any ideas...your help is much appreciated

                      what do you mean by "pass"?

                      Please explain what you are trying to do, and what is going wrong.

                      Do you get error messages (and is error reporting enabled)? What happens / does not happen compared to what you expect?

                        Essentially I am composing four forms, self processing, that upon submission return variables that allow content to appear. A late thought was to remove and replace a html table division as needed, however, heredoc will not pass the division content while I can replace with basic html. As I attempt to code i.e <?php echo $test; ?> in a input values field the html source and input field retain the php code of the echo...any ideas?

                          Additionally, I didn't want to utilize Ajax, javascript while I have yet needed to include any libraries. It was just a hope that I could do the task!

                            tedteeter;11030643 wrote:

                            Essentially I am composing four forms, self processing, that upon submission return variables that allow content to appear. A late thought was to remove and replace a html table division as needed, however, heredoc will not pass the division content while I can replace with basic html. As I attempt to code i.e <?php echo $test; ?> in a input values field the html source and input field retain the php code of the echo...any ideas?

                            traq wrote:

                            what do you mean by "pass"?

                            I'm beginning to suspect you're actually trying to output this content (the way [font=monospace]echo[/font] works) ...?

                            If so, read up on [man]heredoc[/man]s. They are a way to define strings, just like "quotes". A heredoc is not a function or construct: it does nothing on its own. You can assign the string it creates to a variable (using =), or output it to the browser (using [man]echo[/man]), or do a number of other things.

                            At this point, please try to explain, specifically (think small problem, not a general overview), what you're trying to accomplish. It would probably be helpful if you shared some of your code, too.

                              If it is a case of just wanting to output a bunch of HTML, you might be better served by simply getting out of PHP mode at that point:

                              <?php
                              // do some PHP stuff, then...
                              ?>
                              <form action='' method='post'>
                              <input type='hidden' name='foo' value='<?php echo $bar; ?>' />
                              <!-- lots and lots of HTML follows... -->
                              </form>
                              <?php
                              // do some more PHP stuff here
                              ?>
                              

                                In reference to my definition of "Pass", the page retains four different forms an four different "issets" and once the submit button is pressed the "Isset" is encountered and then I assign content to variables,after the form data has been written, which are echo in value fields of the other forms. Perhaps "Pass" isn't the correct term. Anyways I've learned that "heredoc" isn't what I thought after documentation misrepresented the function. Various processes. "super globals" i.e "$REQUEST, $POST" aren't easily utilized in the content while further documentation discusses escaping stuff in the content. I am open to ideas on achieving the content assignment I've described while I understand that "Javascript, Ajax" easily could do the described which I could do without problem....
                                Appreciatively,
                                Ted

                                  Alright...

                                  tedteeter;11030695 wrote:

                                  In reference to my definition of "Pass", the page retains four different forms an four different "issets" and once the submit button is pressed the "Isset" is encountered and then I assign content to variables,after the form data has been written, which are echo in value fields of the other forms.

                                  If I understand correctly, then you need to understand that PHP cannot do things like this. PHP happens first, on the server. Once you send output (e.g., your HTML forms) to the browser, it is gone from PHP and will not come back. It is not possible to interact with the client (browser). PHP does not exist at the same time or place as the webpage you send to the user's browser.

                                  If you want a user's actions to be sent to the server and update the page based on the server's response, then you need AJAX.

                                  tedteeter;11030695 wrote:

                                  Anyways I've learned that "heredoc" isn't what I thought after documentation misrepresented the function. Various processes. "super globals" i.e "$REQUEST, $POST" aren't easily utilized in the content while further documentation discusses escaping stuff in the content.

                                  A heredoc is not a function; it is a way to define a string. I think the manual's definition is actually pretty clear.

                                  In any case, you certainly can use complex variables inside a heredoc:

                                  <?php
                                  
                                  $h = <<< HEREDOC
                                  Use curly braces to put complex variables (i.e., array indexes or object properties) inside a heredoc: 
                                  {$_SESSION['some_index']} works just fine.
                                  HEREDOC
                                  ;
                                  tedteeter;11030695 wrote:

                                  I am open to ideas on achieving the content assignment I've described while I understand that "Javascript, Ajax" easily could do the described which I could do without problem....
                                  Appreciatively,
                                  Ted

                                  As I said above, you're looking for AJAX. Use javascript to submit the form (jQuery has good ajax functions), process the form, and echo the result. When javascript gets the result, you can update the page with the new info.

                                    traq June 30th 2013

                                    The other evening I had composed a note in length to express my appreciation for the "Involved" response that you posted above, however, the note was lost due to a timed out net connection and it was lost...I just wanted to express my sincerest appreciation for your valuable assistance as the encased super global's helped immensely!...Again, thanks to you an all who provided assistance..much appreciated :-)
                                    Ted

                                      no problem, glad to help

                                        Write a Reply...