hello,
i have a problem with strlen. I have written this:
for(y=13,z=0; cInBuf!=' ';y++)
{
cBuf=cInBuf;
z++;
}
len = strlen(cBuf);
out=len/2;
fprintf(outfile,"F%i",out);
If strlen is e.g. 22, it write F22. I want to write F2F2.
How can i do this?... (5 Replies)
Hello,
Just a little problem with the ksh function : strlen
I want to use this function in this little ksh program :
while read line ; do
TOTO=$line
TOTONB=strlen($TOTO)
echo $TOTONB (3 Replies)
Hi all,
I have a perl script which declares two variables and calls another perl script which accesses those variables. But I am unable to access the variables in the called script. My script is as follows:
my $ENV{a}="20";
system("perl called.pl");
and my called.pl contains:
print... (3 Replies)
In a declaration, I have:
const char comment_begin = "<!--";
const char comment_end = "-->";
const int comment_begin_len = strlen(comment_begin);
const int comment_end_len = strlen(comment_end);
When I compile, I get the warnings:
emhttpc.c:64: warning: initializer element is not... (10 Replies)
I have been getting some flack recently for my use of strlen() and strnlen(). Honestly I have always just taken their functionality for granted as being the easiest way of getting the length of a string. Is it really so much better to do pointer arithmetic? What am I gaining besides more... (3 Replies)
Hi!
Some minutes ago I've posted a question related with sed regexps because I need to catch information sended with forms with GET action. This is the post: https://www.unix.com/shell-programming-scripting/127800-regular-expression-sed.html
But now I have a new question. Does cgi scripts have... (0 Replies)
My OS (Debian) and gcc use the UTF-8 locale. This code says that the char size is 1 byte but the size of 'a' is really 4 bytes.
int main(void)
{
setlocale(LC_ALL, "en_US.UTF-8");
printf("Char size: %i\nSize of char 'a': %i\nSize of Euro sign '€': %i\nLength of Euro sign: %i\n",... (8 Replies)
Hello All,
I am getting this error while compiling my application on IBM AIX 5.3.
As I tried to define _XOPEN_SOURCE=500 in makefile, that didn't work.
Please help us to resolve the error. (0 Replies)
Hi! I've a C program as shown below..
The line numbers and the statements of the program are separated by a space..
1 #include<stdio.h>
2 char a,b,c;
3 float x,y,z;
4 int main()
5 {
6 int d,e,f;
7 // further declarations
8 // further declarations
9 /* body*/
10 }
11 void fun1()
12... (1 Reply)
Hello,
This function was copied into my code, which was compiled without error/warning, but when executed there is always Segmentation fault at the end after the output (which seems correct!):
void get_hashes(unsigned int hash, unsigned char *in)
{
unsigned char *str = in;
int pos =... (7 Replies)
Discussion started by: yifangt
7 Replies
LEARN ABOUT PHP
unset
UNSET(3) 1 UNSET(3)unset - Unset a given variableSYNOPSIS
void unset (mixed $var, [mixed $...])
DESCRIPTION unset(3) destroys the specified variables.
The behavior of unset(3) inside of a function can vary depending on what type of variable you are attempting to destroy.
If a globalized variable is unset(3) inside of a function, only the local variable is destroyed. The variable in the calling environment
will retain the same value as before unset(3) was called.
<?php
function destroy_foo()
{
global $foo;
unset($foo);
}
$foo = 'bar';
destroy_foo();
echo $foo;
?>
The above example will output:
bar
To unset(3) a global variable inside of a function, then use the $GLOBALS array to do so:
<?php
function foo()
{
unset($GLOBALS['bar']);
}
$bar = "something";
foo();
?>
If a variable that is PASSED BY REFERENCE is unset(3) inside of a function, only the local variable is destroyed. The variable in the
calling environment will retain the same value as before unset(3) was called.
<?php
function foo(&$bar)
{
unset($bar);
$bar = "blah";
}
$bar = 'something';
echo "$bar
";
foo($bar);
echo "$bar
";
?>
The above example will output:
something
something
If a static variable is unset(3) inside of a function, unset(3) destroys the variable only in the context of the rest of a function. Fol-
lowing calls will restore the previous value of a variable.
<?php
function foo()
{
static $bar;
$bar++;
echo "Before unset: $bar, ";
unset($bar);
$bar = 23;
echo "after unset: $bar
";
}
foo();
foo();
foo();
?>
The above example will output:
Before unset: 1, after unset: 23
Before unset: 2, after unset: 23
Before unset: 3, after unset: 23
PARAMETERS
o $var
- The variable to be unset.
o $...
- Another variable ...
RETURN VALUES
No value is returned.
EXAMPLES
Example #1
unset(3) example
<?php
// destroy a single variable
unset($foo);
// destroy a single element of an array
unset($bar['quux']);
// destroy more than one variable
unset($foo1, $foo2, $foo3);
?>
Example #2
Using (unset) casting
(unset) casting is often confused with the unset(3) function. (unset) casting serves only as a NULL-type cast, for completeness. It
does not alter the variable it's casting.
<?php
$name = 'Felipe';
var_dump((unset) $name);
var_dump($name);
?>
The above example will output:
NULL
string(6) "Felipe"
NOTES
Note
Because this is a language construct and not a function, it cannot be called using variable functions.
Note
It is possible to unset even object properties visible in current context.
Note
It is not possible to unset $this inside an object method since PHP 5.
Note
When using unset(3) on inaccessible object properties, the __unset() overloading method will be called, if declared.
SEE ALSO isset(3), empty(3), __unset(), array_splice(3).
PHP Documentation Group UNSET(3)