May 01
If you are using sessions and use session_register() to register objects, these objects are serialized automatically at the end of each PHP page, and are unserialized automatically on each of the following pages. This basically means that these objects can show up on any of your pages once they become part of your session.
You don’t need to serialize an object before adding it to a session var
example:
<?php include("class.exmaple.php");
$obj = new exampel ();
$_SESSION['obj']=$obj;?>
and to resume the object:
<?php include("class.example.php");
$obj = $_SESSION['obj']); ?>
May 01
<?php
$dirName = 'images';
$dir = opendir($dirName);
while ($filename = readdir($dir)) {
echo $filename . '<br />';
}
closedir($dir);?>
May 01
Please note that if you use a “|” sign in a variable name your entire session will be cleared, so the example below will clear out all the contents of your session.
<?php
session_start();
$_SESSION["foo|bar"] = "foo";
?>
According to this bugreport this behaviour is intended. http://bugs.php.net/bug.php?id=33786
May 01
<?php
// Use of session_register() is deprecated
$hello = "Hello world!";
session_register("hello");
// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["var"] = "Setting this value to the global session variable 'var'.";
// The old way was to use $HTTP_SESSION_VARS
$HTTP_SESSION_VARS["message"] = "Hello world.";
?>
If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made. $_SESSION does not mimic this behavior and requires session_start() before use.
Apr 26
If you want to use split to check on line feeds (\n), the following won’t work:
$line = split("\n", $input_several_lines_long);
You really have to do this instead, notice the second slash:
$line = split("\\n", $input_several_lines_long);
Be advised:
$arr = split("x", "x" );
print_r($arr);
will output:
Array
(
[0] =>
[1] =>
)
That is it will catch 2 empty strings on each side of the delimiter.
Apr 17
If you have mixed characters in html string, use php here document string format.
<?php echo <<<EOF
<!-- template displaying code start-->
<!-- template displaying code end-->
EOF;
?>
Apr 06
A Youtube videóim a következő címen XML Atom csomag formában lekérhetők: http://gdata.youtube.com/feeds/videos?vq=webHauser&max-results=20
A szabványos Google Gdata API programozói interfésszel az ügyes webprogramozók és a professzionális webalkalmazások nyílt hírcstornákon keresztül egyaránt elérhetik és feldolgozhatják a Google (Email, Office, Blog, Picasa, Youtube Video, stb.) felhasználói szolgáltatásait.
Az adatkommunikáció szabványos XML Atom feed csomagok formájában történik, melyet több modern böngésző program formázottan, stíluslappal jeleníti meg, mint pl. Az IE7 vagy FireFox 2.
A telepítéshez a Zend php 5 kiszolgáló szükséges a GData API csomag előzetes telepítésével és könyvtár felvétele a php rendszer könyvtár keresési útvonalában.
http://videoguide.tevagyasztar.com
May 17
However we really see the value of this if we use an each construct
$dummy = asort($phonedirectory);
while(list($person) = each($phonedirectory))
{
echo "".$person;
// that next comma is important!
while (list(,$persondetails) = each($phonedirectory[$person])) {
echo " - ".$persondetails;
}
}
Our out put here is:
Fred Binns - 123 Cleveland - 111-222-5555
Jane Roe - 123 Elm - 111-222-4444
John Doe - 123 Main - 111-222-3333
May 17
Associative two dimensional arrays can be useful as in this phone book example.
//multidemensional associative array
$phonedirectory=array(
"John Doe" => array("123 Main","111-222-3333"),
"Jane Roe" => array("123 Elm","111-222-4444"),
"Fred Binns" => array("123 Cleveland","111-222-5555")
);
echo $phonedirectory["John Doe"][0]." - ".$phonedirectory["John Doe"][1];
Our output here is: 123 Main - 111-222-3333
May 17
$colors=array(
array("red","rgb(255,0,0)"),
array("yellow","rgb(255,255,0)"),
array("green","rgb(0,255,0)"),
array("blue","rgb(0,0,255)")
);
echo $colors[0][0];
echo " - ";
echo $colors[0][1];
echo "<br/>";
This really makes clear to us that what we are creating is in fact an array of arrays.
The output is: red - rgb(255,0,0)
Recent Comments