php

PHP: Converting from UTF-8 HTML

I have a French site that I want to parse, but am running into problems converting the (uft-8) html to latin-1. The problem is shown in the following phpunit test case: class Test extends PHPUnit_Framework_TestCase { private static function fromHTML($str){ return html_entity_decode($str, ENT_QUOTES, 'UTF-8'); } publi...

Debugging C# applications

I´m coming from a PHP background where my debugging "tools" are basically echo, var_dump and exit. While I know the importance of debugging, I never tried to use/learn a debugging tool. Now I´m learning C# and I think I can´t really program without an extensive knowledge of this area. So my question is: where can I learn what is and ho...

"Cut" an element by its key from an array

I've got an indexed array with n elements: Array( 'key1' => 'value1', 'key2' => 'value1', 'key3' => 'value1', ... 'key<i-1>' => 'value<i-1>', 'key<i>' => 'value<i>', 'key<i+1>' => 'value<i+1>', ... 'key<n>' => 'value<n>' ) How to "cut" (ie: copy + remove) the i_th element so the resu...

REGEX: Separe intervals between commas

may be duplicate I am using PHP and postgres. How can I separate words in the form below? The maximun amount of words is 7. word_1, word_2, word_3, ... ...

To get no warning in running PHP in Ubuntu's terminal

I run php test_code.php I get PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/gd.so' - /usr/lib/php5/20060613+lfs/gd.so: cannot open shared object file: No such file or directory in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/mcrypt.so'...

Adding search result with Jquery

Hi Folks, iam trying to setup an little search-engine for my website. I want to add an div for each search result. In the moment i do the following : success: function(data) { if (data[0] == 'nothing') { result = $('#search-result'); result.append('<h3>' + LANG.nothing + '</h3>'); ...

Joomla index redirect

Hi, I want to redirect the index.php to index.html. But in the index.html user has 2 options, 1. to go to a specific section (or) 2. go to actual index.php i.e. our actual site is running with index.php, but we want to highlight a section, so first we want the user to come to index.html & go to mainsite if he wants to. How can I do thi...

Mocking PHP functions in unit tests

I'm unit-testing some PHP code with SimpleTest and I've run into trouble. In my tests of a database class I want to be able to set an expectation for PHPs mysql functions. In my tests of a wrapper class for the mail function I want to mock PHPs mail function. These are just some examples. The point is: I don't (always) want to test if m...

Building MySQL query based on posted variables

This seems like such a simple task, but I'm having a hard time finding a solution that I like for this. I can't find anything I would consider anything other than clunky. Here's what I'm working with: There is a search form that posts variables to the processing script. These variables are the filters for the data being queried. Dep...

Weird glitch with PHP

I need help debugging sample site : http://www.testground.idghosting.com/mma/contact-mma.php in english it's shows the "sent message" even if the form is not filled.. but in french (top right corner link) it doesn' show the fomr at all.... Here is my whole code : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht...

Difference between "->" and "::" in PHP MySQLi OOP

Can anyone tell the difference between mysqli->commit and mysqli::commit? The header in this page is mysqli::commit but in examples they use mysqli->commit I'm confused. ...

Fatal error: Uncaught exception .. using php SwiftMailer

hi I am using SwiftMailer for sending mails and if I try to use dummy email address, for example if I type in "asdf" in email address, I get this uncaught exception. Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [asdf] does not comply with RFC 2822, I am not very experience...

PHP APC in CLI mode

Hi, Does APC module in PHP when running in CLI mode support code optimization? For example, when I run a file with php -f <file> will the file be optimized with APC before executing or not? Presuming APC is set to load in config file. Also, will the scripts included with require_once be also optimized? I know optimization works fine wh...

Getting mySQL date_format to display in PHP

Hi, This could sound like a very simple question to many of you, but I seem to be having trouble getting a basic date_format to work with my mySQL statement and then to be displayed using php. Here is the code that I currently have: $result = mysql_query("SELECT *, DATE_FORMAT('timestamp', '%W %D %M %Y') as date FROM articleDB WHERE ...

Formchecking functions in php

I'm working on a registration form in PHP and I'm wonder what the essential functions are to make sure my database is safe. I'm sure there are a lot of ways to both protect your database or attack one, but I'm asking the advice of stackoverflow: what functions or things must you apply to your data before inserting it into the database. ...

To understand PHP's include -command

I would like to have all variables accessible of the file *handler_login.php* which I include in the file *handler_question.php*. The *handler_question.php* processes the data from the following form. My form_question.php <form method="post" action="handler-question.php"> <p>Title: <input name="question_title" type="text" c...

PHP - Read dynamically generated (and echoed) HTML into a string?

I have a file that pulls some information from the database and creates some relatively simple dynamic HTML. The file can then be used by DOMPDF to turn it into a PDF document. DOMDPF uses GET variables to achieve the basic implementation. ob_start(); include_once("report.php?id=1249642977"); require_once("dompdf/dompdf_config.inc.ph...

Safely executing users' PHP scripts on the server

I'm writing a collaborative project designed to allow code contributions from users. Users will be able to extend a class, add functionality etc, and submit the code back to the server for regular execution. Is there a safe way to execute users' PHP code? A foolproof sanitizing method? What about infinite loops? Or should I offer a diff...

[PHP] file_get_contents - also get the pictures

Hello there everybody! I've run into a problem lately when coding in PHP and file_get_contents. My problem is that when i load a website like this: <? echo file_get_contents($_GET['url']); ?> The pictures of the website i load doesn't show. For example when I go to Google, no pictures are shown. This is for every website i visit. How ...

Php clock 2 hours back

So the clock is 18:37 right now in sweden but it prints out 16:37 why is that? $timestamp = time(); date('M d, H:i', $timestamp) What can be wrong? ...