morris4019 Posted June 24, 2010 Share Posted June 24, 2010 Hi, i've been working on websites on the side to keep my bills paid for awhile now, while getting attending College. I'm even getting my business lisence to start a small professional web design business. It might be because i've spent the last 8 days working 10+ hours in front of the computer staring at code, but I don't really know whats why i cannot seem to get this to work. I have a code section, like the one below. echo "<div style='position:absolute; right: 5px; top: 5px;' > <a name='cb_1' id='cb_1' title='Show/Hide the content of this article.' href='#' onclick=\"if (article_item_1.style.display=='none') { article_item_1.style.display='block'; this.innerHTML='[ Hide Article ]';} else { article_item_1.style.display='none'; this.innerHTML='[ Show Article ]'; } return false;\">[ Hide Article ] </a> <div>"; This website that i am currently creating is for a Real Estate Agent to utilize the MLS search tools (provided by MySkyline), an online buyers guide (dynamic, and editable by the agent) which is loaded in to a <div>, admin tools, user accounts etc. Everything is going great, and i get stumped on this small thing. For some reason i cannot get multi-line statements to echo out. I know this can be done, but I keep getting an "syntax error, unexpected '<' ... on line 94" when i run this code. Now i had originally had the problem of quotes within quotes and that should be fixed by using the escape \ before the double quotes. If this code is all in one line it works, but, this code is being used with a MySQL query and ran multiple times with alot more code to go with it, the end result is not pretty code when it all is contained in one line. Does anyone have any suggestions on what i may be doing incorrectly? Cheers! Michael Link to comment https://forums.phpfreaks.com/topic/205805-multiline-echo/ Share on other sites More sharing options...
Pikachu2000 Posted June 24, 2010 Share Posted June 24, 2010 Uh, you haven't really told us just what about it "doesn't work". Link to comment https://forums.phpfreaks.com/topic/205805-multiline-echo/#findComment-1076938 Share on other sites More sharing options...
ChemicalBliss Posted June 24, 2010 Share Posted June 24, 2010 echo "<div style='position:absolute; right: 5px; top: 5px;' > <a name='cb_1' id='cb_1' title='Show/Hide the content of this article.' href='#' onclick=\"if (article_item_1.style.display=='none') { article_item_1.style.display='block'; this.innerHTML='[ Hide Article ]';} else { article_item_1.style.display='none'; this.innerHTML='[ Show Article ]'; } return false;\">[ Hide Article ] </a> <div>"; I cannot see anything wrong with this code, is this the exact code your using? Just in case: treat echo as a function call, enclose the string in parenthesis (). -cb- Link to comment https://forums.phpfreaks.com/topic/205805-multiline-echo/#findComment-1076940 Share on other sites More sharing options...
morris4019 Posted June 24, 2010 Author Share Posted June 24, 2010 Uh, you haven't really told us just what about it "doesn't work". Sorry, i thought I did with the error message. It does not run, the page will not load, i get a "Parse error: syntax error, unexpected '<' in ....on line 94" (94 being the second line of what i quoted, starting "<a...."). I guess what i'm asking is why this particular 4 line echo statement might not work (as in at all)? As state above, i could condense the entire echo statements code (and all the rest once i put it back in) and it will work fine, but for some reason the echo's string "" (to be displayed) is not working if it is on multiple lines. Also, with all the code that is being generated in a loop (id/names changing for each one) and running about 50 times (or however news entries might be in the database at the time) the code looks horrible, each section very very long, hence why i would like to break it up and have some structure to the code. Cheers! Michael Link to comment https://forums.phpfreaks.com/topic/205805-multiline-echo/#findComment-1076941 Share on other sites More sharing options...
morris4019 Posted June 24, 2010 Author Share Posted June 24, 2010 Ok, well, opened another RockStar and, not really sure what i did, but it is now working. So thank you everyone for look at that for me. I really can't believe how quickly a reply had posted after i wrote the initial question. I'm adding this forum to my favorite bar right now. If i need anything else i will come here first. Cheers! Michael Link to comment https://forums.phpfreaks.com/topic/205805-multiline-echo/#findComment-1076945 Share on other sites More sharing options...
Pikachu2000 Posted June 25, 2010 Share Posted June 25, 2010 Uh, you haven't really told us just what about it "doesn't work". Sorry, i thought I did with the error message. It does not run, the page will not load, i get a "Parse error: syntax error, unexpected '<' in ....on line 94" (94 being the second line of what i quoted, starting "<a...."). I guess what i'm asking is why this particular 4 line echo statement might not work (as in at all)? As state above, i could condense the entire echo statements code (and all the rest once i put it back in) and it will work fine, but for some reason the echo's string "" (to be displayed) is not working if it is on multiple lines. Also, with all the code that is being generated in a loop (id/names changing for each one) and running about 50 times (or however news entries might be in the database at the time) the code looks horrible, each section very very long, hence why i would like to break it up and have some structure to the code. Cheers! Michael You're right; you did. I evidently looked right past it, sorry about that! Link to comment https://forums.phpfreaks.com/topic/205805-multiline-echo/#findComment-1076988 Share on other sites More sharing options...
Andy-H Posted June 25, 2010 Share Posted June 25, 2010 $html = <<<HTML <div style="position:absolute; right: 5px; top: 5px;" > <a name="cb_1" id="cb_1" title="Show/Hide the content of this article." href="#" onclick="if (article_item_1.style.display=='none') { article_item_1.style.display='block'; this.innerHTML='[ Hide Article ]';} else { article_item_1.style.display='none'; this.innerHTML='[ Show Article ]'; } return false;">[ Hide Article ] </a> <div> HTML; echo $html; http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Try that. //Edit Also, check the line above the echo statement for errors such as a missing semicolon. This is most likely the problem. Link to comment https://forums.phpfreaks.com/topic/205805-multiline-echo/#findComment-1076993 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.