Jump to content

[SOLVED] How do you call a function within a function please.


redarrow

Recommended Posts

How do you call a function within a function please.

 

<?php

function plugins(){


function plugin_quiz(){

	$quiz_quistion="<center>";
	$quiz_quistion.='Do dogs eat human flesh!';
    $quiz_quistion.="<br><br>";
    $quiz_quistion.="<form method='POST'>";
    $quiz_quistion.="<select name'quiz_quistion'>";
    $quiz_quistion.="<option value='yes'>Yes</option>";
    $quiz_quistion.="<option value='no'>No</option>";
    $quiz_quistion.="</select>";
    $quiz_quistion.="<br><br>";
    $quiz_quistion.="<input type='submit' name='submit' value='send'>";
    $quiz_quistion.="</form>";
    $quiz_quistion.="<center>";
    
    return($quiz_quistion);
}


	function plugin_message_form(){

	$message_form="<center>";
	$message_form.="<form method='POST'>";
	$message_form.="Subject";
	$message_form.="<br>";
	$message_form.="<input type='text' name='subject'>";
	$message_form.="<br><br>";
	$message_form.="Name";
	$message_form.="<br>";
	$message_form.="<input type='text' name='name'><br>";
	$message_form.="<br><br>";
	$message_form.="Message";
	$message_form.="<br>";
	$message_form.="<textarea cols='30' rows='20'></textarea>";
	$message_form.="<br><br>";
	$message_form.="<input type='submit' name='submit' value='send'>";
    $message_form.="</center>";

    return($message_form);
}

}
?>


<?php echo plugins(plugin_quiz()); ?>

Link to comment
Share on other sites

I am trying to design a code, that lets me plug a plugin ( like the ones below)  into,

a web site, without the need of redesigning the web site.

 

 

so if i design a plugin i ask the user to just add a page to the project with a include.

 

dynamically. (not using just include lol)

 

but how?

 

so the question is, how do you design a plugin to integrate to a existing web site.

 

<?php

   $plugin="plugin_message_form";


   
switch ($plugin){


CASE "plugin_quiz":

	$quiz_quistion="<center>";
	$quiz_quistion.='Do dogs eat human flesh!';
    $quiz_quistion.="<br><br>";
    $quiz_quistion.="<form method='POST'>";
    $quiz_quistion.="<select name'quiz_quistion'>";
    $quiz_quistion.="<option value='yes'>Yes</option>";
    $quiz_quistion.="<option value='no'>No</option>";
    $quiz_quistion.="</select>";
    $quiz_quistion.="<br><br>";
    $quiz_quistion.="<input type='submit' name='submit' value='send'>";
    $quiz_quistion.="</form>";
    $quiz_quistion.="<center>";
    
    echo $quiz_quistion;
    

    BREAK;


	CASE "plugin_message_form":

	$message_form="<center>";
	$message_form.="<form method='POST'>";
	$message_form.="Subject";
	$message_form.="<br>";
	$message_form.="<input type='text' name='subject'>";
	$message_form.="<br><br>";
	$message_form.="Name";
	$message_form.="<br>";
	$message_form.="<input type='text' name='name'><br>";
	$message_form.="<br><br>";
	$message_form.="Message";
	$message_form.="<br>";
	$message_form.="<textarea cols='30' rows='20'></textarea>";
	$message_form.="<br><br>";
	$message_form.="<input type='submit' name='submit' value='send'>";
    $message_form.="</center>";

    echo $message_form;
    
    BREAK;
     
              }
              ?>

Link to comment
Share on other sites

 

This is what i got so far.

 

oop no good, to hard.

 

<?php

   $plugin="plugin_message_form";

   
   function function_plugin_quiz(){
   	    
   	    $quiz_quistion="<center>";
	$quiz_quistion.='Do dogs eat human flesh!';
    $quiz_quistion.="<br><br>";
    $quiz_quistion.="<form method='POST'>";
    $quiz_quistion.="<select name'quiz_quistion'>";
    $quiz_quistion.="<option value='yes'>Yes</option>";
    $quiz_quistion.="<option value='no'>No</option>";
    $quiz_quistion.="</select>";
    $quiz_quistion.="<br><br>";
    $quiz_quistion.="<input type='submit' name='submit' value='send'>";
    $quiz_quistion.="</form>";
    $quiz_quistion.="<center>";
    
    return($quiz_quistion);
   	
   }
   
   
   function function_message_form(){
   	
   	$message_form="<center>";
	$message_form.="<form method='POST'>";
	$message_form.="Subject";
	$message_form.="<br>";
	$message_form.="<input type='text' name='subject'>";
	$message_form.="<br><br>";
	$message_form.="Name";
	$message_form.="<br>";
	$message_form.="<input type='text' name='name'><br>";
	$message_form.="<br><br>";
	$message_form.="Message";
	$message_form.="<br>";
	$message_form.="<textarea cols='30' rows='20'></textarea>";
	$message_form.="<br><br>";
	$message_form.="<input type='submit' name='submit' value='send'>";
    $message_form.="</center>";

    return($message_form);
   }

   
switch ($plugin){


CASE "plugin_quiz":

	echo function_plugin_quiz();

    BREAK;


	CASE "plugin_message_form":

	echo function_message_form();
    
    BREAK;
     
              }
              ?>

Link to comment
Share on other sites

well i done it and find it easier then oop thanks.

 

But like you say, oop will be worth studying.

 

SOLVED

 

<?php

$plugin="plugin_quiz";


$function_switch_info=array("plugin_quiz"=>"function_plugin_quiz","plugin_message_form"
=>"function_message_form");

function function_plugin_quiz(){

$quiz_quistion="<center>";
$quiz_quistion.='Do dogs eat human flesh!';
$quiz_quistion.="<br><br>";
$quiz_quistion.="<form method='POST'>";
$quiz_quistion.="<select name'quiz_quistion'>";
$quiz_quistion.="<option value='yes'>Yes</option>";
$quiz_quistion.="<option value='no'>No</option>";
$quiz_quistion.="</select>";
$quiz_quistion.="<br><br>";
$quiz_quistion.="<input type='submit' name='submit' value='send'>";
$quiz_quistion.="</form>";
$quiz_quistion.="<center>";

return($quiz_quistion);

}


function function_message_form(){

$message_form="<center>";
$message_form.="<form method='POST'>";
$message_form.="Subject";
$message_form.="<br>";
$message_form.="<input type='text' name='subject'>";
$message_form.="<br><br>";
$message_form.="Name";
$message_form.="<br>";
$message_form.="<input type='text' name='name'><br>";
$message_form.="<br><br>";
$message_form.="Message";
$message_form.="<br>";
$message_form.="<textarea cols='30' rows='20'></textarea>";
$message_form.="<br><br>";
$message_form.="<input type='submit' name='submit' value='send'>";
$message_form.="</center>";

return($message_form);
}



foreach($function_switch_info as $key=>$val){

switch ($plugin){

	CASE "$key":

		echo $val();

		BREAK;

}
}
              ?>

Link to comment
Share on other sites

 

Here a test, for the dynamic plugin's

 

what it all about.

 

I wanted a way to have dynamic plugin's for each page, so user's

only have to update one page.

 

and add the new dynamic plugin to the page.

 

below full example.

 

 

plugin.php

<?php session_start();


$plugin=$_SESSION['pluged_in'];

$function_switch_info=array("plugin_quiz"=>"function_plugin_quiz","plugin_message_form"
=>"function_message_form");


function function_plugin_quiz(){

$quiz_quistion="<center>";
$quiz_quistion.='Do dogs eat human flesh!';
$quiz_quistion.="<br><br>";
$quiz_quistion.="<form method='POST'>";
$quiz_quistion.="<select name'quiz_quistion'>";
$quiz_quistion.="<option value='yes'>Yes</option>";
$quiz_quistion.="<option value='no'>No</option>";
$quiz_quistion.="</select>";
$quiz_quistion.="<br><br>";
$quiz_quistion.="<input type='submit' name='submit' value='send'>";
$quiz_quistion.="</form>";
$quiz_quistion.="<center>";

return($quiz_quistion);

}


function function_message_form(){

$message_form="<center>";
$message_form.="<form method='POST'>";
$message_form.="Subject";
$message_form.="<br>";
$message_form.="<input type='text' name='subject'>";
$message_form.="<br><br>";
$message_form.="Name";
$message_form.="<br>";
$message_form.="<input type='text' name='name'><br>";
$message_form.="<br><br>";
$message_form.="Message";
$message_form.="<br>";
$message_form.="<textarea cols='30' rows='20'></textarea>";
$message_form.="<br><br>";
$message_form.="<input type='submit' name='submit' value='send'>";
$message_form.="</center>";

return($message_form);
}



foreach($function_switch_info as $key=>$val){

switch ($plugin){

	CASE "$key":

		echo $val();

		BREAK;

}
}
              ?>

 

 

page1.php

<?php 

include("header.php");

if(isset($_SESSION['pluged_in'])){

unset($_SESSION['pluged_in']);

}else{

	$_SESSION['pluged_in']='plugin_message_form';
}

session_start();


if($_SESSION['pluged_in']='plugin_message_form'){

require_once("plugin.php");

$_SESSION['pluged_in']='plugin_message_form';

include("footer.php");

}
?>

 

page2.php

<?php

include("header.php");

if(isset($_SESSION['pluged_in'])){

unset($_SESSION['pluged_in']);
}else{

$_SESSION['pluged_in']='plugin_quiz';
}



session_start();


if($_SESSION['pluged_in']='plugin_quiz'){

require_once("plugin.php");

$_SESSION['pluged_in']='plugin_quiz';

include("footer.php");

}

?>

 

 

index.php

<?php

include("header.php");

include("footer.php");

?>

 

header.php

<html>
<head>
<title>welcome</title>
</head>
<body>
<center>
<h1>welcome to my web site</h1>
<br><br>
<a href="page1.php">message me</a>
<br><br>
<a href="page2.php">quiz</a>
<br><br>

 

footer.php

<br><br>
<hr>
redrrow test
<hr>
</center>
</body>
</html>

Link to comment
Share on other sites

unless I"m misunderstanding you, all you are wanting to do is have a central file like functions.php, and include that on all other pages.  That way, if you add another function, you can just put it on that one page functions.php, and any page can access it.  Is that right?  Well then dude, you are way over complicating this... You don't need any of those session vars or conditions or nothing.  You don't need to be passing any of that stuff man.  Just put the functions on the page and when you include the file on the page, the page automatically has access to whatever is in there. 

 

It boggles my mind that you think what you've done makes any kind of sense, whatsoever.  I'm not calling you stupid.  I just can't for the life of me figure out what the hell goes on inside that head of yours.  You are an anomaly.  You deserve some kind of on-going study about, well, you.  We should start a thread detailing your actions around here.  Make a documentary.  I bet discovery would eat that shit up. You'll be famous!

Link to comment
Share on other sites

You make me lath,that was a insult but also a cool joke.

 

I was creating a function file, that sits on a server, where the users have no access and,

i can re create there stupid requests, via one page, every think is dynamic.

 

my i dears look crazy, and are crazy but i still get buy.

 

your way is the correct way and i no that but wanted to be diffrent.

 

 

 

Link to comment
Share on other sites

nah man, not trying to be insulting, just honest.

 

I can never understand half the things you say.  I know english isn't your first language.  I'm pretty sure you've mentioned that, a few times.  But seriously, I'm dying to know, Do you know english, at all?  Again, not calling you stupid.  You don't have to know english to be smart.  In fact, learning english probably makes you stupider, if anything.  I envy you; all I know is english.

 

I just get the impression sometimes that you take what is posted, run it through google translator, respond to it in your native language, run it through the google translator to english, and post that. Again, no offense. I just find stuff like this interesting.

 

 

Link to comment
Share on other sites

yes i am English lol, and from London but blind, so i can not understand every think so quickly like the average person, and yes, i use a speaking program to understand posts.

 

i am not thick or got no brain or a retard as you think.

 

done well in life till i lost all my eye sight but love life.

 

why don't you close your eyes, and sit in the black and type and see it it easy, then try to do programming.

 

then ask agin.

 

Link to comment
Share on other sites

I guess not. It could be a bit of motive to not bother typing full sentences though... Idk.

 

Anyway yeah, classes aren't actually that hard. They're basically just containers for functions, but with a bit more useability. Worth learning tbh. Plus apparently, you get paid more for knowing OOP. Not that I've been paid for programming ever before; but that's what I've heard.

Link to comment
Share on other sites

You'd be surprised how many people in the paid-for-web-dev world use classes but don't understand the point, and it coulda just been written as regular functions.

 

You constantly hear how there's a high demand for web developers and you scratch your head wondering how that can be true when it seems like every kid on the planet is an aspiring script-kiddie...and that's the key phrase right there: script-kiddie.  A good chunk of people out there getting paid to do this stuff don't really know all the ins and outs of it.  So when you hear that there's a high demand for web developers, what people are really saying is there's a high demand for good web developers.

Link to comment
Share on other sites

Lol well, we were all script kiddies once :P

 

Well...I just made an sql class which basically has all of the "useful" sql functions. At the moment I'm using mysql, but if I wanted to use sqlite or something else, I could easily just change this class a bit and my whole site would be sqlite compatible. That's a good reason for using a class surely? It wouldn't work as individual functions, as they all need to use the same vars. Well...it would, but I'd need to global or define a whole load of stuff.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.