Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to write a simple HTML code inside PHP echo ” “;

  • This topic is empty.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #42027
    ajnoguerra
    Participant

     ONMOUSEdown=”document.images.src=’images/linkedin.png'”>
     ONMOUSEdown=”document.images.src=’images/facebook.png'”>

    How do I write this code inside PHP echo ” “;

    echo “




    ?>

    I tried writing it just like the above code but it doesn’t work.

    #121152
    Andy Howells
    Participant

    Need to add a ; to the end of your echo after the closing quote mark.

    #121163
    __
    Participant

    just so you know, this:

    echo “

    <.img src='images/linkedin-icon.png' onMouseDown='document.images['large'].src='images/linkedin.png' ' />
    <.img src='images/facebook-icon.png' onMouseDown='document.images['large'].src='images/facebook.png' ' />
    <.img src=' ' name='large'>

    ” ;

    and this:

    ?>
    <.img src='images/linkedin-icon.png' onMouseDown='document.images['large'].src='images/linkedin.png' ' />
    <.img src='images/facebook-icon.png' onMouseDown='document.images['large'].src='images/facebook.png' ' />
    <.img src=' ' name='large'>

    are *exactly* equivalent.

    Also, when writing HTML (or anything else that may have quote marks), it’s usually much easier to use the HEREDOC notation:

    $string = <<< HTML
    Hello, I’m using “quotes” left and right, and I don’t need to escape them.
    I can still use $variables in my text,
    or even {$nested}.
    A “HEREDOC” is like a “double-quote” string,
    but it starts with three less-than brackets ( <<< )
    followed by a token (anything; I used “HTML” here)
    and ends when the token appears at the beginning of a line
    (by itself, no indentation at all),
    with a semicolon by itself on the next line.
    Have a try!
    HTML
    ;

    #121167
    Rai
    Member

    Try this:


    your html here

    your html here

    your html here

    #121204
    ajnoguerra
    Participant

    Thank you for all your answers ( @Rai, @traq, @AndyHowells ). One problem that I keep on encountering with that code is the pure html works and does swap image but when I try to incorporate it inside PHP, it doesn’t work anymore. That is why i’m looking for a work around on how to write it inside PHP because I will be getting the image source from a database if only those code will work. :( Please help…

    #121209
    __
    Participant

    Well, what do you mean by “doesn’t work”?

    What actually happens vs. what you expected?

    Did you make sure error reporting is enabled, and do you get any error messages?

    #121217
    ajnoguerra
    Participant

    @traq, Sorry if I sound a little confusing. The pure HTML markup with a little javascript I posted does a “swap image”. The small/thumbnail images when clicked , a bigger version of that image will appear below. But then when I try to rewrite the code inside PHP and run it in a browser, it doesn’t do anything when you click the thumbnail image but I didn’t get any error messages.

    #121218
    __
    Participant

    @ajnoguerra what does the output HTML look like?

    #121222
    ajnoguerra
    Participant

    @traq, I’m glad you’re really trying to help me. Here’s the output >>> [swap image](http://codepen.io/ajnoguerra/pen/kdsnD “simple-swap-image”)

    #121231
    __
    Participant

    > Here’s the output

    That seems to work as expected, unless I misunderstand your problem.

    Are you sure you posted the **output** HTML (i.e., the HTML *that is generated by PHP* and demonstrates your problem)?

    #121314
    ajnoguerra
    Participant

    mysql_connect(“localhost”,”root”,””) or die (mysql_error());
    mysql_select_db(“motoactiv-db”) or die (mysql_error());

    $sql = “Select * FROM products”;
    $result = mysql_query($sql);
    while($record=mysql_fetch_array($result))
    {
    ?>

    }
    ?>

    I still haven’t figured out the problem with this because when I tested it out in Firefox and IE it works just fine but when I tried it with Chrome, it doesn’t make the bigger image come out, it is as if no javascript was implemented. @traq

    #121335
    __
    Participant

    @ajnoguerra – see my comment in your other thread.

    #121339
    noahgelman
    Participant

    >

    Why are you escaping the quotes? You don’t need to do that. You only need to do that when the quotes are the same as the surrounding quotes. If your html is inside double quotes, you don’t need to escape single quotes.

    #121341
    natashakimly
    Member

    wow such a great info. [http://adiphene.webs.com](http://adiphene.webs.comhttp://adiphene.webs.com&#8221;)

Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘Back End’ is closed to new topics and replies.