Inline PHP in HTML - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Programming > PHP Development

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-31-2009, 09:44 PM   #1 (permalink)
Junior Member
 
Join Date: Dec 2009
Posts: 2
Default Inline PHP in HTML

Hi,
I'm new here and to PHP, just trying to get some good PHP knowledge. It'd be nice if I could receive any sort of help.

I am having trouble making a code piece work:

PHP Code:
<?php
function onMouseOver()
{
    echo 
"<script type='text/javascript'>window.alert('Mouseover called')</script>";
}
?>

<a href='blahblah.php' onmouseover='"<?php onMouseOver() ?>"'> <img name="item1" src="../aboutus.bmp" /></a>
In the code above, I'm simply trying to call the function onMouseOver(); using the onmouseover property from href. The problem is that the window.alert function is being called when I enter the page when it is supposed to call the window.alert function when I mouseover the image?

I even tried to put the whole code in php:
PHP Code:
<?php
function onMouseOver()
{
    echo 
"<script type='text/javascript'>window.alert('Mouseover called')</script>";
}
?>

<?php echo "<a href='blahblah.php' onmouseover='".onMouseOver()."' > <img name='item1' src=../aboutus.bmp' /></a>" ?>
Still doesn't work? For some reason!

Any ideas, anyone?!

Edit: Nevermind, I found a workaround.

Last edited by enden; 01-01-2010 at 01:06 AM. Reason: Figured it out
enden is offline   Reply With Quote
Sponsored Links
Old 01-01-2010, 01:50 AM   #2 (permalink)
Junior Member
 
Join Date: Dec 2009
Posts: 42
Default Re: Inline PHP in HTML

looking at the function i dont see the code is suppose to call the windows alert when the mouse is scrolled over.


if you can tell me what exactly you want to achieve I can try and code for you
mackson is offline   Reply With Quote
Old 01-01-2010, 06:01 AM   #3 (permalink)
Junior Member
 
Join Date: Dec 2009
Posts: 2
Default Re: Inline PHP in HTML

I figured out what I need to do thanks!!
enden is offline   Reply With Quote
Old 01-06-2010, 06:56 PM   #4 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 4
Default Re: Inline PHP in HTML

for future readers, just to let you know that PHP is a server-side language. It cannot be activated from within an HTML document, it only runs when someone accesses a page, and is used to create dynamic contents on the page to send to the user. therefore, by calling the php function above, the code within the php function was executed and the <script>...</script> was added to the page before being sent to the user.
vanguard is offline   Reply With Quote
Old 01-08-2010, 12:46 AM   #5 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 28
Default Re: Inline PHP in HTML

I'm also new in php and I wanted to learn more. I saw some site that are .html extension but a it has a php code in it and that's what I want to find out.
ryanne is offline   Reply With Quote
Old 01-08-2010, 05:20 AM   #6 (permalink)
Junior Member
 
Join Date: Jan 2010
Posts: 4
Default Re: Inline PHP in HTML

Thats a setting within a number of HTTP daemons like Apache and litespeed. You can set which file extensions are handled with which script parser (such as PHP). You can set any file extension to be parsed with PHP, ASP, CF etc.. which is why you sometimes see websites with non-standard file extensions such as .page. This effect can also be achieved with .htaccess files if you want to use this feature without access to the daemon config settings.
vanguard is offline   Reply With Quote
Old 01-19-2010, 11:10 PM   #7 (permalink)
Regular User
 
Tharaka Deshan's Avatar
 
Join Date: Jan 2010
Location: Galle, Sri Lanka
Posts: 15
Default Re: Inline PHP in HTML

I am agree with vanguard, how you call a php function from a client side mouse over detecting from a server side script.
But you can do it by using a javascript to detect mouseover at client side and let that javascript to call a php function.It is possible to do so.
Tharaka Deshan is offline   Reply With Quote
Old 03-28-2010, 05:26 PM   #8 (permalink)
Member
 
novintabligh's Avatar
 
Join Date: Mar 2010
Posts: 106
Send a message via Yahoo to novintabligh
Default Re: Inline PHP in HTML

you cannot call javascript functions in php. php is server side while java script is client side.
novintabligh is offline   Reply With Quote
Old 06-29-2010, 08:39 AM   #9 (permalink)
Junior Member
 
Join Date: Jun 2010
Posts: 20
Default Re: Inline PHP in HTML

I am having problems getting inline PHP to work correctly. If I do
"""
<?php
printf("<html><body><p>The time is %s.</p></body></html>", date("g:i a", time()));
?>
"""
it will print "The time is 10:08 am."

However, if I do
"""
<html><body><p>The time is <?php date("g:i a", time()) ?>.</p></body></html>
"""
all I get is "The time is ." printed to the screen. What am I missing in either php.ini or http.conf to get this inline php to work correctly.
alstonwillman is offline   Reply With Quote
Old 07-09-2010, 02:46 PM   #10 (permalink)
Junior Member
 
Join Date: Jul 2010
Posts: 73
Default Re: Inline PHP in HTML

your function is allready echo something. you shoud return that script in first instance
johnny.dacu is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 02:58 PM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting