473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to define a new global function?

Very frequently, I need to use codes like this to see output clearly:

$a=print_r($var,true);
echo "<pre>$a</pre>";

How can convert this piece of code to a global function (for example:
echopre) in Php so that I can use echopre($data) anywhere in php
program (in my server)?

Thanks,

Aug 17 '07 #1
4 21704
Rik
On Fri, 17 Aug 2007 19:00:12 +0200, Ming <mi*******@gmail.comwrote:
Very frequently, I need to use codes like this to see output clearly:

$a=print_r($var,true);
echo "<pre>$a</pre>";

How can convert this piece of code to a global function (for example:
echopre) in Php so that I can use echopre($data) anywhere in php
program (in my server)?
Define the function somewhere? Functions are always in scope, there are no
'local' or 'global' functions. So just put this code somewhere in the
beginning/in a functions-include file:
<?php
function echopre($a){
$a=print_r($var,true);
echo "<pre>$a</pre>";
}
?>
--
Rik Wasmus
Aug 17 '07 #2
On Aug 17, 10:03 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 19:00:12 +0200, Ming <minghu...@gmail.comwrote:
Very frequently, I need to use codes like this to see output clearly:
$a=print_r($var,true);
echo "<pre>$a</pre>";
How can convert this piece of code to a global function (for example:
echopre) in Php so that I can use echopre($data) anywhere in php
program (in my server)?

Define the function somewhere? Functions are always in scope, there are no
'local' or 'global' functions. So just put this code somewhere in the
beginning/in a functions-include file:
<?php
function echopre($a){
$a=print_r($var,true);
echo "<pre>$a</pre>";}

?>
--
Rik Wasmus
Thanks Rik.

I want to make it as a stand function come with php. i.e.: I want to
make it anywhere I can use echo.
Aug 17 '07 #3
Rik
On Fri, 17 Aug 2007 19:05:31 +0200, Ming <mi*******@gmail.comwrote:
On Aug 17, 10:03 am, Rik <luiheidsgoe...@hotmail.comwrote:
>On Fri, 17 Aug 2007 19:00:12 +0200, Ming <minghu...@gmail.comwrote:
Very frequently, I need to use codes like this to see output clearly:
$a=print_r($var,true);
echo "<pre>$a</pre>";
How can convert this piece of code to a global function (for example:
echopre) in Php so that I can use echopre($data) anywhere in php
program (in my server)?

Define the function somewhere? Functions are always in scope, there are
no
'local' or 'global' functions. So just put this code somewhere in the
beginning/in a functions-include file:
<?php
function echopre($a){
$a=print_r($var,true);
echo "<pre>$a</pre>";}

?>
--
Don't quote signatures please.
I want to make it as a stand function come with php. i.e.: I want to
make it anywhere I can use echo.
Hmm, I'm not sure I understand. You want it to be a function that's
automatically available in every script run on the server, without
calling/defining it in the script? You could set an auto_prepend_file in
php.ini with the function definition.
--
Rik Wasmus
Aug 17 '07 #4
On Aug 17, 10:12 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 19:05:31 +0200, Ming <minghu...@gmail.comwrote:
On Aug 17, 10:03 am, Rik <luiheidsgoe...@hotmail.comwrote:
On Fri, 17 Aug 2007 19:00:12 +0200, Ming <minghu...@gmail.comwrote:
Very frequently, I need to use codes like this to see output clearly:
$a=print_r($var,true);
echo "<pre>$a</pre>";
How can convert this piece of code to a global function (for example:
echopre) in Php so that I can use echopre($data) anywhere in php
program (in my server)?
Define the function somewhere? Functions are always in scope, there are
no
'local' or 'global' functions. So just put this code somewhere in the
beginning/in a functions-include file:
<?php
function echopre($a){
$a=print_r($var,true);
echo "<pre>$a</pre>";}
?>
--

Don't quote signatures please.
I want to make it as a stand function come with php. i.e.: I want to
make it anywhere I can use echo.

Hmm, I'm not sure I understand. You want it to be a function that's
automatically available in every script run on the server, without
calling/defining it in the script? You could set an auto_prepend_file in
php.ini with the function definition.
--
Rik Wasmus
Terrific help.

Many thanks!

Aug 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: David WOO | last post by:
Hi, I am a newbie on C++, I need to define some global variables which should be accessible to most classes. In the mean time, I don't won't the global variables be modified freely at most of...
97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
34
by: Dennis | last post by:
I would like to dynamically allocate in a sub a 2 dimensional Array float *myarray = new float ; of course I get an error. How do you allocate a 2D array using the New operator? I...
6
by: Peng Yu | last post by:
I want to define a macro #define FILEWR(FILENAME) which can be expanded to #ifndef OUTFILE #define OUTFILE ofstream out; #endif
6
by: David T. Ashley | last post by:
Hi, In my project, I typically declare and define variables in the .H file, i.e. DECMOD_MAIN UINT8 can_message_201_status_global #ifdef MODULE_MAIN = HAS_NEVER_BEEN_RECEIVED #endif ;
18
by: Bryan Parkoff | last post by:
"#define" can only be inside the global scope before main() function. "#if" can be tested after "#define" is executed. The problem is that "#define" can't be inside main() function. I do not wish...
17
by: Davor | last post by:
How to define global variable in main()? I'm asking because I have an array in main, whose size is determined by input, so the definition has to be in main ( or in some other funcion ). And I need...
4
by: Mohammad Omer Nasir | last post by:
I was read Linux kernel code in which I saw few define macro defines in functions. The snap of the function is following and file name "err_ev6.c". static int ev6_parse_cbox(u64 c_addr, u64...
1
by: lumumba401 | last post by:
Hello everybody, i am asking about how to define a bidimensional dynamic array as a global variable to use as incoming variable in a function Let us see , for example in a part of a programm...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.