Hello,
I have the following code which,currently im running on my local machine.I am making a call to a php script called getxml.php,which should send the contents of an xml file as the response.
But,instead of a GET request, in Firebug i see that an OPTIONS request is being made, like
OPTIONS getxml.php . I think im not making a cross...
I have a unique case where I have an array like so:
$a = array('a' => array('b' => array('c' => 'woohoo!')));
I want to access values of the array in a manner like this:
some_function($a, array('a')) which would return the array for position a
some_function($a, array('a', 'b', 'c')) which would return the word 'woohoo'
So basicall...
When my script starts, I have:
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
And then, I register my custom error handler with PHP:
function handleError($code, $text, $file, $line) {
echo "&%!!";
return true;
}
set_error_handler('handleError');
Next, there comes some code...
I have about 90% of the PHP code done for a really nice facebook connect integration with my social network but I am having 1 huge problem.
This code below is supposed to show a facebook connect button on the page but instead it show nothing at all.
<body onload="initFB();">
<fb:login-button length="long" background="light" size="medi...
I've got a csv file I'm parsing with PHP. (Actually, it's tab-separated.) In a text editor, the file looks like this:
Object Id Page/Master Id Page/Master Name ...
Using this code:
$f = file_get_contents($filepath);
echo $f;
I get this in the browser:
��O�b�j�e�c�t� �I�d� �P�a�g�e�/�M�a�s�t�e�r� �I�d� �P�a�g�e�/�M�a�s�t�e�r� �N�...
I try to register a shutdown function to log an fatal error. Nice stuff, if it would work for my class...
Inside a method I do this:
register_shutdown_function(array($this, 'handleFatalError'));
handleFatalError is not static, and it's public:
public function handleFatalErrors() {
if(is_null($e = error_get_last()) === false) {
...
I use both of them to handle all sorts of errors, even Fatal Errors. My callback functions get called when an error happens, but I keep getting this big red error info box with the stack trace. My visitors shouldn't see that at all! never!
To be sure, both callbacks return true. Actually that should disable the PHP's default error proce...
I have a log() method and want to log the name of the script that called it. How is that possible in PHP?
...
while ($row = mysql_fetch_object($result)) {
$data[] = $row;
echo "<div id='captionbox' style='width: 110px;float:left;color:#FFF;text-align:center;'>";
echo "<a href='#' class='thumb'><img class='thumb-img' value = ".$row->aid." onclick='getVote(".$row->aid.", \"".$row->atitle."\")' src='images/roadies/th".$row->aid.".jpg' ...
Re: Kohana v2.3.4.
Do I have to create a new controller for every URL which uses segment 2? In other words, if I want my URLs to be:
www.example.com/foo
www.example.com/bar
... do I need to create a unique controller for foo and a unique controller for bar? I'd like to create just one controller, if possible.
EDIT:
I'd like to avo...
I'm trying out the PEAR HTML_BBCodeParser script on my home server. For some reason, the script displays backslashes () before single and double quotes in the text after being parsed. I've skimmed through the code, but can't find the place where it does this. Might have missed something--the file is 900 lines long! If anybody knows what ...
Example:
set_error_handler(array($this, 'handleError'), E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE);
what does that suppose to mean?
...
Hey!
I am creating a small php framework and I have a few classes that use the singleton design pattern. Like for example my Session class uses the singleton pattern because in theory I will only really need one instantiation of the class.
I recently discovered the registry pattern (actually new about it for a while but it sort of cam...
I use register_shutdown_function() to let PHP call a function at any time my script crashes. After I've logged that to a file, I want to display a beautiful error-sorry-message to the user.
To do that, I want to clean the current output buffer. I think there's a stack of output buffers (not sure), so the big question is if I could simp...
Like one of those "Error 404" pages, I wish to show the visitor an error page with a fat sorry message in the case a script crashes. I use register_shutdown_function() to register a callback function. But the problem is, probably, that headers were already sent. However, maybe you know a good possibility to do that?
...
What is the best way to check if an image is unique using PHP? Say I have a directory of about 30 images (about 500*500 pixels), and someone uploads another picture, what is a good way to check if the uploaded image is not yet in the directory?
Is there some sort of way to create hash's of images which can be easily compared? I then cou...
How can a random number be generated from scratch, i.e without using any built-in features of the language / outside API that will help with the randomization process?
For example php has a rand() function and a seed function, and I'm sure java also has some similar stuff.
You can use built-in functions to get the current time etc, but...
Say we have a UTF-8 string $s and we need to shorten it so it can be stored in N bytes. Blindly truncating it to N bytes could mess it up. But decoding it to find the character boundaries is a drag. Is there a tidy way?
[Edit 20100414] In addition to S.Mark’s answer: mb_strcut(), I recently found another function to do the job: grapheme...
When establishing a new PDO db handler, I've got to wrap everything into a try-catch to prevent an error message that would print all db access data to the user.
But how about all the other methods like exec(), for example? Must I wrap all of these into a try-catch block? At which point is the PHP documentation telling that an method th...
I've read some related questions (1, 2), but none seemed fully adequate.
What's the best way to access globally important objects in each class or .php script? A few examples:
DB (database)
Cache (memcache wrapper)
Logger (custom)
CurrentUser (details about the currently logged in user)
Some options I've seen include:
Relying on ...