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…
Way to verify if variable is a valid GD image resource?
I have a class that accepts a GD image resource as one of its arguments. As far as I know, there is no way to type hint this since it is a resource and not an object. Is there a way to validate …
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 …
Cannot get php display_errors enabled
Hey i know there are a few posts regarding this topic and i have scoured them all! I cannot not enable the display_errors setting in php no matter what i do!!! Im using virtual box with php 5.3 …
Error in mysql fetch error in php
Hi when i run my code this proplem apper this is my code Answer rewrite so this: becomes this:
Parent Child Relationships PHP/MYSQL
I have a table like this: id name parent_id I then want to select certain rows based on their id, so something like this: SELECT * FROM TABLE WHERE id IN (‘1’, ‘5’, ‘8’, ‘9’, ’35’) …
Does PHP allow *.properties file as in Java?
Is there a way to use a *.properties file in PHP as you do in Java? I’d like to store some application-level constants in a properties or XML file and easily call them from throughout my code. Your …
GET URL parameter in PHP
I’m trying to pass a URL as a url parameter in php but when I try to get this parameter I get nothing I’m using the following url form: I’m trying to get it through: But nothing returned. What is the problem? Answer $_GET is not a function or language construct—it’s just a variable (an…