Skip to content

Tag: php

PHP XSS sanitization

Questions: What are the best safe1(), safe2(), safe3(), and safe4() functions to avoid XSS for UTF8 encoded pages? Is it also safe in all browsers (specifically IE6)? . Many people say the absolute best that can be done is: . . There are a hell of a lot of posts about PHP and XSS. Most just say “use HTM…

PHPExcel very slow – ways to improve?

I am generating reports in .xlsx using PHPExcel. It was okay in the initial testing stages with small data sets (tens of rows, 3 sheets), but now when using it on a real production data with over 500 rows in each sheet, it becomes incredibly slow. 48 seconds to generate a file, and when running a report that …

PHP regular expression

What is purpose of the following code? What kind of $string match this expression? Why there is a character @? Answer That regular expression will match any <script>…</style> or <style>…</style> (X)HTML blocks in the string and remove them. This is most likely done to preve…

Mock private method with PHPUnit

I have a question about using PHPUnit to mock a private method inside a class. Let me introduce with an example: How can I stub the result of the private method to test the some more code part of the public function. Solved partially reading here Answer Usually you just don’t test or mock the private &a…

Are numeric and associative arrays in PHP two different things?

This is a deeper dive into a previous question I had here: Can items in PHP associative arrays not be accessed numerically (i.e. by index)? According to W3Schools, : In PHP, there are three kind of arrays: Numeric array – An array with a numeric index Associative array – An array where each ID key…

Altering .htaccess with PHP – removing a rewrite rule

I am using PHP to remove/add static pages once a page has been deleted, I want to be able to remove it from the .htaccess, however I’ve tried this, but it throws an error: Warning: preg_replace() [function.preg-replace]: Unknown modifier ” in … The code: This is an example of what it should …