Current location: Hot Scripts Forums » Programming Languages » PHP » php variable problem


php variable problem

Reply
  #1 (permalink)  
Old 05-21-05, 12:17 PM
ashishjha54 ashishjha54 is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Post php variable problem

hello to all,
i want to create a variable in my webpage that will contain source -codes of languages and echo it when necessary.say,
$source='php code or c code or sql code';
echo $source;
but the problem is that whenever i put php code or sql code or any code in $source and try to execute it .the php code inside $ source starts executing .is it possible that whatever code i put in $source ,it is taken as text string and echo it as test whenevr we need it.it should not get executed and it should not interfere with the rest of the php code.
in short ,i just want to source code in $source variable and print it on the webpage.how can i do it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-21-05, 12:40 PM
liljoeyjordison liljoeyjordison is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Use single quotes ' instead of double quotes " so

$foo = ' date(d M Y h:i a) ' ;
echo $foo ;

will output date(d... instead of 28 Apr 2005 10:44 am

Last edited by liljoeyjordison; 05-21-05 at 12:43 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-21-05, 01:12 PM
ashishjha54 ashishjha54 is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
i want to print the source code not its output
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-21-05, 01:22 PM
ashishjha54 ashishjha54 is offline
Newbie Coder
 
Join Date: May 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
i tried putting it within single brackets but it gives erros saying wrong syntax
i am using this
$source='<?php
if ( !defined('MODULE') )
{
die("access denied");
}

//Here we define out main variables
$welcome_string="Welcome!";
$numeric_date=date("G");

//Start conditionals based on military time
if($numeric_date>=0&&$numeric_date<=11)
$welcome_string="Good Morning!";
else if($numeric_date>=12&&$numeric_date<=17)
$welcome_string="Good Afternoon!";
else if($numeric_date>=18&&$numeric_date<=23)
$welcome_string="Good Evening!";

//Display our greeting
echo "$welcome_string";

?>
';
and it gives parsing error.i want to print the contents of $source variable.

Last edited by ashishjha54; 05-21-05 at 01:23 PM. Reason: spelling mistake
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-21-05, 01:28 PM
liljoeyjordison liljoeyjordison is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ashishjha54
if ( !defined('MODULE') )
You have single quotes in the variable, so it ends the string. Try using
if ( !defined("MODULE")) instead
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-22-05, 05:11 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
highlight_string()

Edit:
Quote:
Originally Posted by liljoeyjordison
You have single quotes in the variable, so it ends the string. Try using
if ( !defined("MODULE")) instead

Single quotes is fine, actuatly a LOT better than double quotes.

Edit:
Add slashes to the string...
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 05-22-05, 11:14 AM
liljoeyjordison liljoeyjordison is offline
Newbie Coder
 
Join Date: Jan 2005
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Oh yeah, forgot about that
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 05-22-05, 01:09 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$source='<?php

if ( !defined(\'MODULE\') ) 

die("access denied"); 


//Here we define out main variables
$welcome_string="Welcome!";
$numeric_date=date("G");

//Start conditionals based on military time
if($numeric_date>=0&&$numeric_date<=11)
$welcome_string="Good Morning!";
else if($numeric_date>=12&&$numeric_date<=17)
$welcome_string="Good Afternoon!";
else if($numeric_date>=18&&$numeric_date<=23)
$welcome_string="Good Evening!";

//Display our greeting
echo "$welcome_string";

?>
'
;

echo 
highlight_string(stripslashes($source), true);
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can someone help with htaccess and php problem tigherrdk PHP 6 03-09-09 03:28 AM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 09:26 AM
Passing a PHP variable in Javascript??? todayscoffee JavaScript 2 01-08-05 10:45 AM
Passing a PHP variable in Javascript??? todayscoffee PHP 2 01-04-05 02:56 PM
Can anyone help me ? (problem using php variables in html db insert code) chronic_ PHP 2 06-13-04 12:19 PM


All times are GMT -5. The time now is 12:19 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.