Complex Php Echo Statement Assistance - Can't quite get this one, help appreciated

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Complex Php Echo Statement Assistance - Can't quite get this one, help appreciated

jlhaslip
Can someone help me out with this one, please.
I have a PHP script in which I am trying to write a fairly complex piece of html and I can't seem to get the coding of the PHP echo statement. There are single and double quotes scattered throughout this line of html and it is driving me nuts attempting to manage the output. So far, the only way I can get it to work is to break the echo'ing of the line of html code into the following lines of PHP:
HTML
echo "\t" ;
echo '<li><a href="';
echo $full_dir . $file ;
echo '" alt="full-size"><img src="' ;
echo $dir . $file ;
echo '" alt="' ;
echo $dir . $file ;
echo '" ><img src="' ;
echo $mid_dir . $file ;
echo '" alt="mid-size" class="preview" /></a></li> ';
echo "\n\r\t";

The script is managing to correctly output a string of html as follows:
HTML
<li>
<a href="full_images/pict0023.jpg" alt="full-size">
<img src="images/pict0023.jpg" alt="images/pict0023.jpg" >
<img src="mid_images/pict0023.jpg" alt="mid-size" class="preview" /></a>
</li>

I have broken it down into segments with carriage returns in this example, but it could be a single, continuous piece of code, too.

This sample of PHP code works correctly in a Browser, so it isn't an issue with the 'correctness' of the html, it has to do with the complexity of the single and double quotes and the PHP required to output this line as one string instead of the 11 echo statements.

I will continue to make some attempts, but so far I just am not managing to sort out the method of escaping the right pieces of code and arranging all the bits and pieces. Any suggestions for cleaning up and leaning out this code would be appreciated.

 

 

 


Reply

Inspiron
Try this echo instead..

CODE

echo "\t";
echo "<li><a href='";
echo $full_dir . $file;
echo "' alt='full-size'><img src='";
echo $dir . $file;
echo "' alt='";
echo $dir . $file;
echo "' ><img src='";
echo $mid_dir . $file;
echo "' alt='mid-size" class='preview' /></a></li> ";
echo "\n\r\t";


Basically I've swapped " to become the first and last instead of using '.
I believe " has higher priority than ', hence " should comes first.

Reply

WindAndWater
It's quite late here (I just got back from working on a project all night), so I might not be thinking strait, but I'm fairly sure that you need to escape quotes if you use them more than once. Also, I don't see why you can't use more concatenations instead of echo commands to make it cleaner.
Try:

HTML
echo "\t" ;
echo "<li><a href=\"" . $full_dir . $file . "\" alt=\"full-size\">";
echo "<img src=\"" . $dir . $file . " alt=\"" . $dir . $file . "\" / >";
echo "<img src=\"" . $mid_dir . $file . " alt=\"mid-size\" class=\"preview\" />";
echo "</a></li>";
echo "\n\r\t";



I have no idea whether it'll work as it's completely off the top of my head, but it seems reasonable, and it's quite a bit cleaner code.

 

 

 


Reply

OpaQue
Even though this point is not relavant to the topic, I still feel like adding it.
When using complex statements of printing, use the code "print".

QUOTE
There is a difference between echo and print, but speed-wise it should be irrelevant which one you use. print() behaves like a function in that you can do: $ret = print "Hello World";And $ret will be 1.
That means, that print can be used as part of a more complex expression where echo cannot.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : complex, php, echo, statement, assistance, appreciated

  1. Need Help With Php Echo
    (2)
  2. What Is Wrong With This Php-sql Select Where Statement?
    (5)
    Hi all Im having problems with this peice of code: CODE   $result =
    mysql_query("SELECT 'ID' FROM 'login' WHERE
    username=$dusername",$link);      if($result != NULL){
        //username DOES exsist so they cant have it!
        include("scripts/userexsists.php"); The idea is, this query will take the
    variable $dusername which is the usernbame that a user wants to have, and check it in the
    database to see if it already exsists. and depending on whether it does or not it will inc....
  3. Question For The If And Echo Function
    (2)
    I'm not that good with PHP, and I tried this code: CODE if (
    $_SERVER['REQUEST_URI'] == ('/') )/*'/' is the
    domain root*/ { echo('<img src="{I_ONEURL}" border="0"
    alt="{T_SOMETHING}" />'); } else { echo('<img
    src="{I_ANOTHERURL}" border="0" alt="{T_SOMETHING}" />'); }
    However, it doesn't work. So, basically, I want that if the request is at the root (actually
    mysubdomain.domain.com), it will show {I_ONEURL....
  4. Php Website Assistance?
    Help Me (1)
    Hello, i have just set up a website, and want to protect the site using login and password
    protection. Can anyone give me some PHP scripts which will keep a track of usernames and passwords,
    and add them to the access rights list. is this possible? If so, i would be much obliged if you
    would do so. Thank you. P.S If anyone needs assistance with HTML, that is my speciality, so send
    me a message. Always happy to help....
  5. Calling A Variable From A Dynamic List In A Sql Statement
    (2)
    I would be greatful if anyone could help me out, I have been stuck on this for a while. The problem
    is that I have a drop down menu which I get the contents of from a database. Then when I press the
    get details button I want to use the value selected in my drop down menu and pass it into an SQL
    statement to recieve all te relevent info. Everything works if I specify a known variable, but the
    problem seems to be passing a variable in which is part of the array. Below is the code for the drop
    down menu and the Sql statement i'm trying to execute. drop down menu: �....
  6. Elseif Statement Not Doing The Right Thing
    (3)
    CODE elseif
    ("$username=''.$password=''.$fullname=''.$countr
    y=''.$email=''") { print "<table border='0'
    align='center' valign='center' width='400'
    height='400'><tr><td align='center'><font
    size='2'><b>You did not fill out all the fields</b><br><A
    HREF='javascript:history.back()'><img
    src='http://www.online.trap17.com/images/go_backb....
  7. Simple Shoutbox?
    I only know the echo part of php... (19)
    Well, does anyone have a nice simple shoutbox php code? It's just I've been looking for one
    for a while but they all seems to have millions of files attached with them and everything. Just
    wondering if theres anything simpler out there?....
  8. I Will Provide You With A Php Code That..
    ..enable you to use the 'echo' command. (0)
    **YOU DO NOT NEED ANY HTML TAGS FOR THIS SCRIPT**** Enter all values between the ' ' quotes
    //Define The Variables $cfg = array('sitename' => '', //Your Sites Name
    'footer' => '', //OPTIONAL, if you want your footer stored so that the
    echo command can display it. Ex: Copright ©2005 - Michael Fratello (the © is will turn
    into the copyright 'c') 'board_dir' => '', //Link to your
    message boards. (If you have any) ); ?> I recommend saving this file ....
  9. Possible To Put An If Statement Inside A Variable?
    (2)
    Ok, so I'm using the include() function on my website. Problem is I'm trying to include a
    search engine form into the layout which is stored in a variable, except the form has an if
    statement in it and I can't seem to get it working. Here's the code I'm trying to
    include... CODE Search: > Just wondering if it is possible for me to put this
    form with the if statement into a variable, or if there's another way that I could go about
    doing this. Thanks.....
  10. Learning PHP
    Need some assistance (13)
    Hello All, I am learning PHP. I have been reading several tutorials and such but what I am
    wondering is this: is there a site that recomends simple project programs to practice your coding?
    Or can someone recommend a few programs I could write to get better. Kind of like learning it in
    school - after you learn it, you get an assignment to go practice it. Thanks, Dennis....

    1. Looking for complex, php, echo, statement, assistance, appreciated

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for complex, php, echo, statement, assistance, appreciated

*MORE FROM TRAP17.COM*
advertisement



Complex Php Echo Statement Assistance - Can't quite get this one, help appreciated



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE