Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu May 08, 2003 5:43 am Reply with quote

This question has been asked and answered more times than I can recall. There is a PHP built in way to do this that is very simple and fool-proof.

First I will show you an example and then explain it.
Code:


$someVarName = <<<_JSCODE_
<script>alert('Hello World');</script>
_JSCODE_;

echo $someVarName;

That's it! You simply insert your JavaScript code as you use it in your HTML document and drop it in. You do not have to escape any quotes or anything special. If it works in native HTML, it should work here.

Now for a caveat. You can use PHP variables in the code WITHOUT using the <? ?> tags. Here would be an example of that.
Code:


$messageText = 'Hello World';

$someVarName = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;

echo $someVarName;

Now, if you were using this in a block, you need to assign all content to the $content variable. You could do this in a separate line of code, like this
Code:
$messageText = 'Hello World';


$someVarName = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;

$content = $someVarName;
or just assign the block to $content instead of $someVarName like this.
Code:
$messageText = 'Hello World';


$content = <<<_JSCODE_
<script>alert('$messageText');</script>
_JSCODE_;


There is only 1 very important syntactical rule for usage. In my example _JSCODE_ is analogous to a BLOCK TAG. These tags can be named whatever you want, as can the $someVarName. However, the ending block tag MUST be left aligned AND there can be no character EXCEPT a carriage return after either of the block tags.

Note that this is standard PHP code functionality. You can use it anywhere to insert any non PHP code directly into your PHP scripts.


Last edited by Raven on Thu Oct 09, 2003 8:30 pm; edited 1 time in total 
View user's profile Send private message
dragonfly
New Member
New Member



Joined: Aug 31, 2003
Posts: 2

PostPosted: Sun Aug 31, 2003 7:08 pm Reply with quote

Works good. I used this helpful info to make a collapsing content menu...

There were some questions in the nukecops forums too, but I think I'll post here instead.

Thanks!
 
View user's profile Send private message
Raven







PostPosted: Sun Aug 31, 2003 7:11 pm Reply with quote

Thanks so much! BTW, this method in PHP is called HEREDOC if you want to read up on it.
 
dragonfly







PostPosted: Sun Aug 31, 2003 10:52 pm Reply with quote

Raven wrote:
Thanks so much! BTW, this method in PHP is called HEREDOC if you want to read up on it.


Smile

Yeah.. I have not yet read a lot about HEREDOC, but I do have a few books on javascript, cgi, perl, php, asp etc.

I'll look into HEREDOC a little more after I integrate WEFT for IE browsers.. fun stuff - looks like a challenge anyways. If you've heard of anyone using WEFT in phpnuke, please let me know.
 
CodyG
Life Cycles Becoming CPU Cycles



Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island

PostPosted: Tue Nov 18, 2003 10:26 am Reply with quote

I've been trying to use WHEREDOC in a form and I'm not getting anywhere. It's something like this:

Code:


<?php
// All the opening module stuff

$form_block = "

// then a lot of html form stuff

$content = <<<TERMS

//more html about terms and conditions

TERMS;

//then more form stuff and cases and the submit

";

echo "$form_block";

CloseTable();
include("footer.php");
?>



Until now I've been calling this rather long bit of html from the language file as a define.

I'm not having much success with WHEREDOC method in this case. Am I trying to put a variable inside a variable? Can you use WHEREDOC inside a variable? Raven, can you clue me in to how to approach this?
 
View user's profile Send private message
Raven







PostPosted: Tue Nov 18, 2003 10:41 am Reply with quote

$form_block is 1 variable and $content is another. From your code I don't understand what you are trying to do - sorry. $content contains your terms so it is just a regular string to php. Use it as you would any other string. You are echoing $form_block but never echoing $content so it will never appear anywhere. Try
Code:
<?php 

// All the opening module stuff

$form_block = " // then a lot of html form stuff ";

$form_block .= <<<TERMS

//more html about terms and conditions

TERMS;

$form_block .= " //then more form stuff and cases and the submit ";

echo $form_block;

CloseTable();
include("footer.php");
?>
 
pure
New Member
New Member



Joined: Jan 07, 2004
Posts: 8

PostPosted: Wed Jan 07, 2004 11:14 pm Reply with quote

Hi Raven,

Just wondering should I paste all my code here or should I just make a zip file and send it to you. Which ever way let me know and thanks a lot.
 
View user's profile Send private message
Raven







PostPosted: Thu Jan 08, 2004 10:02 pm Reply with quote

Normally you can place your javascript code in includes/my_header.php. If you place it w/i the PHP tags, then you must either use the WHEREDOC or echo statments. I recommend the WHEREDOC syntax. Then, you can modify your themes or possibly place the code that calls the javascript in mainfile.php.
 
pure







PostPosted: Sat Jan 10, 2004 8:51 pm Reply with quote

Hi Raven,

Here's what I am trying to do and the files I am using along with the code.

Basically I want to display a menu created by xara webstyle in a block on left or right side.

I am not a php guru or anything like that I am still trying to learn my way around php. I am having hard time displaying this menu block.

When I created the menu with xara webstyle it creates the following files.
1. SideBar.html
2. sidebar.js
3. xaramenu.js
4. all the .gif files

Here's the path where I have place all these files.

/public_html/pm/modules/SideBar
SideBar.html sidebar.js and xaramenu.js

/public_html/pm/images/blocks
all the images .gif files

Than I created a block-SideBar.php and placed it here
/public_html/pm/blocks

Here's the code in my block-SideBar.php
Code:


<?
include = ("public_html/pm/modules/SideBar/SideBar.html");
?>


It did not work did not display the menu.

After reading your thread I created another php file called index.php and upload to

/public_html/pm/modules/SideBar
and now I have 4 files there, SideBar.html, sidemenu.js, xaramenu.js and index.php

My index.php has the following code.
Code:


<?
$content = <<<_JS_
<script src=\"/public_html/pm/modules/SideBar/index.php\"></script>
_JS_;
?>


And I changed the code in block-SideBar.php to this
Code:


<?
include = ("public_html/pm/modules/SideBar/index.php");
?>


It still did not work. Can you please help me with this? Can you tell me what I am doing wrong and which file I need to place in which folder?

I would really appriciate it. Thank you.
 
Raven







PostPosted: Sat Jan 10, 2004 10:54 pm Reply with quote

Without looking at the files I can't tell you about those. However, your include syntax is in error. When you include a file you use this type syntax
Code:
include("file.html");
 
pure







PostPosted: Sat Jan 10, 2004 11:15 pm Reply with quote

Which files do you want to look at? Let me know I will paste them here. Thanks
 
pure







PostPosted: Tue Jan 13, 2004 1:10 am Reply with quote

No replies yet?

Maybe this is a tuff one. Wink
 
Raven







PostPosted: Tue Jan 13, 2004 9:15 am Reply with quote

I was waiting to hear if correcting your include syntax helped or not.
 
pure







PostPosted: Tue Jan 13, 2004 2:47 pm Reply with quote

Raven wrote:
I was waiting to hear if correcting your include syntax helped or not.


Oh ok. Sorry I misunderstood.

Ok when I change the code to point to index.php
Code:


include("/public_html/pm/modules/SideBar/index.php");


And try to display the block and hit refresh I get an error "A runtime error has occured. Do you wish to Debug? Line:1 Error: Syntax error"

And I can see the block on the right but empty nothing in it.

If I change the code and point to SideBar.html
Code:


include("/public_html/pm/modules/SideBar/SideBar.html");


I still get the same Syntax error but this time the block on the right says
"There isn't content right now for this block."

By The Way here's all the code in the files

block-SideBar.php
Code:


<?php

if (eregi("block-SideBar.php", $_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

include("/public_html/pm/modules/SideBar/index.php");

?>


OR
Code:


include("/public_html/pm/modules/SideBar/SideBar.html");



index.php
Code:


<?php

if (eregi("index.php", $_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

$content = <<<_JS_

<script src=\"/public_html/pm/modules/SideBar/xaramenu.js\"></script>
<script src=\"/public_html/pm/modules/SideBar/sidebar.js\"></script>
_JS_;

?>


SideBar.html
Code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SideBar</title>
</head>
<body bgcolor="#ffffff" text="BLACK">
<script src="xaramenu.js"></script><script Webstyle4 src="sidebar.js"></script>
</body></html>
 
pure







PostPosted: Thu Jan 15, 2004 9:15 pm Reply with quote

Hello!!! Rolling Eyes
 
dcasmr
Worker
Worker



Joined: Feb 06, 2004
Posts: 147

PostPosted: Sun Feb 20, 2005 5:51 pm Reply with quote

Here we go the second time. I added the proper spaces to avoid some conflicts with my post. Please note that wherever you see added spcaes, it is not due to misspelling.

I have on my site a folder named talkdata. [ Only registered users can see links on this board! Get registered or login! ] If I open in a normal browser window the attached codes, I get a javas cript link and when I double click on the link, I get the pop-up window.

I am trying to add as module to my Main Menu the link portion so that whenever someone clicks on that module, the pop-up window will open.
Note: the HTML posted must be called from the folder [ Only registered users can see links on this board! Get registered or login! ]

I have read a few post and even tried creating a module, but with no success.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Musee de Manega - Brendologie</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>
<sc ript language="JavaS cript" type="text/JavaS cript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</sc ript>
<a href="#" onClick="MM_openBrWindow('manegapopup.html','popWimpy','width=450,height=185')">
Musee de Manega</a>
</body>
</html>
 
View user's profile Send private message
Raven







PostPosted: Sun Feb 20, 2005 8:39 pm Reply with quote

You need to set this up as a block or a nuke module called index.php. Then, if you simply echo this code or include it, it will work.
 
dcasmr







PostPosted: Sun Feb 20, 2005 10:03 pm Reply with quote

I have tried before creating a module with no luck. Attached are the codes for the module.
1. clicked on, the module does not trigger the pop-up window, but rather opens another window with the link for the pop-up..
2. When I click on the link, nothing happens.

Since the HTML must be opened from a a directory in my nuke site, talkdata, I have used talkdata/manegapopup.html, /talkdata/manegapopup.html with no luck



<?php
#### Generated by Module Creator - By Disipal site (www.disipal.net) ####
if (!eregi("modules.php", $PHP_SELF)) {
die ("You can't access this file directly...");

}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
//get_lang($module_name);
include("header.php");
$index = 0;
OpenTable();
echo"<p>"
. "<sc ript language=\"JavaS cript\" type=\"text/JavaS cript\">"
. "<!--"
. "function MM_openBrWindow(theURL,winName,features) { //v2.0"
. " window.open(theURL,winName,features);"
. "}"
. "//-->"
. "</sc ript>"
. " <a href=\"#\" onClick=\"MM_openBrWindow('manegapopup.html','popWimpy','width=450,height=185')\">"
. "Musee de Manega</a>";
CloseTable();
include("footer.php");

?>
 
Raven







PostPosted: Sun Feb 20, 2005 10:18 pm Reply with quote

Why is it a module instead of a block?
 
dcasmr







PostPosted: Sun Feb 20, 2005 10:40 pm Reply with quote

A module or a link would be preferable since I want to save space on the main page. Also, I wanted to just add it with my Main Menu.
With a link, I can add it to my site with sommaire parametrable.
 
Raven







PostPosted: Sun Feb 20, 2005 10:41 pm Reply with quote

Then just add it to your blocks/blocks-modules.php file.


Last edited by Raven on Sun Feb 20, 2005 11:38 pm; edited 1 time in total 
dcasmr







PostPosted: Sun Feb 20, 2005 10:59 pm Reply with quote

Raven,

I pm you so that you can see what I have as far how it works. Then, if I can re-write the whole thing to the pop-up window as an href link, I could add it to sommaire.
 
Raven







PostPosted: Sun Feb 20, 2005 11:38 pm Reply with quote

Sorry, I meant blocks/blocks-modules.php
 
dcasmr







PostPosted: Mon Feb 21, 2005 12:53 am Reply with quote

I am totally stuck. When I look at blocks/modules.php I just see PHP codes and do not know how to add the link to it without breaking the codes -Smile

I am very much interested in a solution and will be looking to make a block also.
 
Raven







PostPosted: Mon Feb 21, 2005 12:59 am Reply with quote

See if this helps
[ Only registered users can see links on this board! Get registered or login! ]
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©