The fifth version of the PHP: Hypertext Preprocessor (PHP) scripting language. It features the Zend Engine 2, better object model support, and many other improvements over PHP 4.
3
votes
1answer
86 views
Create an object when you need it! in PHP
Well Iam trying to learn OOP for a while now, My idea here is to create a simple CMS kind of thing.And I did something like this:
App Class:
...
4
votes
2answers
92 views
Implementation of a Custom Database Class
Following Database Class is what I'm using as a wrapper to connect with MySqli in a application, and below the class is how i'm implementing it currently I'm not sure if this is the right way to ...
1
vote
1answer
38 views
Correctly display the count() for an empty json_decode object result
The objective of this piece of code is to get a message from a cryptocurrency daemon through RPC and extract the transactions object to pass it to the view. Is there a simpler / less ugly way of doing ...
0
votes
0answers
29 views
PHP Function Style
I've written a small to medium size LAMP application and I'm in the process of refactoring the code.
I started with subsystems in separate files, and used includes to use them. I've move all those ...
1
vote
1answer
66 views
PHP handle array when query database with one-to-many relationship
Well, I am writing a web service using PHP to return data from a DB in JSON format. I need to query 3 tables, which have a one-to-many relationship, like shown below:
...
2
votes
1answer
54 views
Doctrine/Symfony WHERE clause for reports
I'm trying to generate a report from two doctrine entities.
The fields to filter the report are optional. This is the code I've got now and it looks really bad to me. How can I improve this?
...
0
votes
1answer
86 views
Searching a CSV with PHP
Given a string, I've done the below to search a CSV for a keyword and display the row if it's found
...
0
votes
2answers
86 views
Nested file_get_contents / json_decode
I have this code but it takes over a minute to run. I'm looking at around 400 entries being brought back for the first loop. Any ideas on how it could be improved for speed?
...
1
vote
0answers
63 views
Merge sort in PHP - my first algorithmic exposure to PHP 5
I have this small program in PHP implementing merge sort. I used one rather simple run time optimisation via using one additional array which allows faster merge operations:
...
3
votes
1answer
117 views
Array wrapper concept with method chaining that provides a fluent interface
I've been working on a class(2 actually) that wraps around the array data structure of PHP. It doesn't bring anything new to the table, it simple makes the function ...
3
votes
1answer
90 views
Cookie wrapper made for fun
This was mostly made for fun, so I don't see it having any real world purpose any time soon.
...
2
votes
1answer
212 views
Combining json responses of recursive web service calls with PHP and curl
I'm implementing the Hotel Price List API from Skyscanner. This requires a first call to the service to implement a session followed by 1 or more calls to the service to get the actual results. I've ...
0
votes
1answer
174 views
Split words that are too big
I need to optimize the below code, as much as possible in:
using less resources as possible
being as fast as possible
What the code does is simple, it splits the string by words and only if a word ...
1
vote
1answer
83 views
Create multi-dim array from cursor
I'm executing a cursor. I have cut off the code how the procedure is called and executed. This part is efficient. At last I have a small cursor. I'm calling the procedure, which returns this cursor ...
1
vote
2answers
192 views
Finding a word with the most occurrences of a character
I am new to PHP development. So Kindly, review my code and guide me make it better/optimize. Currently, it works well with inputs that I have tried.
...
0
votes
2answers
98 views
PHP program which extracts attribute lists from custom tag
PHP program which extracts attribute list from the custom tag. It also strips out the single and double quote if it exists around attribute value.
...
0
votes
2answers
48 views
Lookup class to get descriptions of values
Following yesterday's advice on my Customer class, I have now created a new class which is for looking up descriptions from a MySQL database. I have a Lookup table which contains type, name, value, ...
3
votes
1answer
204 views
Simple customer SQL query using a class and function
I have been writing PHP for a number of years but in a procedural style. I have always shied away from object oriented PHP because I just didn't understand it. However now I'm back for another go.
I ...
5
votes
1answer
95 views
PHP Class code that allow developers to register taxonomies in a CMS
Building complex applications can sometimes be a pain when extending or editing later on; I read online about the S.O.L.I.D principles of OOD, I want to understand if I am following a good approach ...
3
votes
1answer
69 views
PHP class which preserves line break by splitting the line into as many line break as it have
Can anyone here please review my PHP code which preserves line break by splitting the line into as many line break as it have?
...
0
votes
2answers
378 views
How to use PHP Visibility method?
At my new job, with new young developers, we are seriously discussing improving code structure and performance. (They keep more than 80 lines of code in a method). However I've read more tutorials, ...
6
votes
1answer
129 views
A Search Engine Class
I've built a Search Engine class for a website that permits to search companies in base of their locations and their categories (companies pay a plan to be found in the places that they will).
In the ...
-1
votes
1answer
68 views
Authorizing users for POST requests
I've to authorize some users to do POST requests from their CMSs in order to create a new resource on my database. I've to send a JSON response containing the status of the response (successful or not)...
2
votes
1answer
112 views
Forum project using OOP PHP
I've been developing a forum as my first OOP project, I've successfully built a login/registration and other functionality typical in forums.
I'm looking for some guidance in terms of where to take ...
1
vote
1answer
50 views
Validation of uploading images and adding records to the database
I am doing a php project with the codeigniter framework. In my controller, I have a function that does the following.
Uploads an image to the server
Add a row to the database. The data would be ...
2
votes
1answer
343 views
PHP/MySQLi code for registration/login form
The following code works, I just want to know if there are any suggestions as to how I can make it better or more secure. Thanks.
config.php:
...
1
vote
1answer
35 views
Bulk customer creation
Here is my script which takes 50k records from a CSV and does CRUD operation with them. Unfortunately there are a lot of issues with the performance.
CSV fields are: msisdn, resellerid, product
...
2
votes
1answer
543 views
Using PHP's password_hash and password_verify for a login function
This is my first time using password_hash and password_verify in PHP. Would this be the correct usage of ...
0
votes
1answer
76 views
Inserting a role using PDO
My question has to do with :
(a) Can this be made more secure?
(b) Are there best practices in relation to setting timezone?
(c) What best approach should be taken defining use of utf8?
...
3
votes
2answers
264 views
Get number from N
I'm trying to find the shortest and best way to achieve the following:
Given input integer $N, get the following output:
n = 0, output = 0
n = 1, output = 0
n = 2, output = 10
n = 3, output = 100 ...
3
votes
3answers
93 views
Scrape HTML into separate files for each chapter
I have written a program to read HTML file, find particular text, write text from that particular text to next particular text in a newly opened file. I am interested in code review. I am very new PHP....
1
vote
1answer
70 views
Mapping a product its corresponding image file
I'm writing this method that elaborates an image name..
I think my logic is not being the best one here but I'm not very savvy in programming yet.
Right now it looks like this:
...
3
votes
3answers
260 views
PHP form validation for name, email, and Twitter handle
Given the following input values from a form, create a method or
methods to validate the input based on their requirements. Throw an
exception if any data is invalid.
1.1 ...
5
votes
1answer
115 views
Multilanguage class that detects and sets language
I have been learning object oriented programming for quite a while. I understand many concepts about it but I quickly realized that I made a big mistake just reading theory and not doing any actual ...
3
votes
1answer
51 views
Nesting a flat array in on itself
I have an extremely large function for turning my database output of menu links into a multidimensional array that nests each of the links in a menu fashion. I'm wondering if anyone sees a way this ...
2
votes
1answer
119 views
OPP Sign In/Out procedure in PHP
As a self-taught student of Web-Development and Web Technologies, I created a simple sign in/out form in PHP, just for practice purposes and some fun!
I read the O'reilly's book about PHP and I found ...
4
votes
1answer
281 views
Simple Notification class that models database
I'm updating a website I made awhile ago from a functional design to an OOP design. There are still a lot of functions below this class that I haven't implemented yet but I'm getting to it (such as <...
1
vote
1answer
74 views
Updating register_globals code for importing $_GET and $_POST data
I'm updating a bunch of PHP code that relies on register_globals and uses request data globally. In the process of fixing/updating I spend a lot of time writing ...
1
vote
1answer
47 views
Calculating a quality score of something based on attributes
I'm willing to have a way to calculate a quality score of an object; in this case an addressbook contact.
I believe there are way better approaches to do this and I'd like to hear your references.
...
2
votes
1answer
121 views
Class that generates records after performing business logic
I wrote a small class that does a database lookup and it generates a collection/Array. The Collection is resorted based on values returned from the database. Finally, the records can be retrieved ...
3
votes
2answers
106 views
Classes, one responsibility principle and magic methods
I am currently building a small application that allows users to create a slideshow, each slideshow consisting of slides that are either videos or images. Although this will be relatively small at ...
2
votes
3answers
221 views
PHP page pagination
I think my code is sloppy can anyone give me advice to do it better?
This is a page pagination that get rows from mysql db and calculate the number of pages.
...
2
votes
1answer
604 views
Secure array encryption and decryption
I have written the below class which encrypts and decrypts a PHP array. The encrypted data and the hash are sent over an insecure connection and I would appreciate if you could check the code for any ...
2
votes
1answer
228 views
Regular Expression for parsing PHP annotations containing multiple lines and markup
I am writing a regular expression for parsing PHP annotations in a flexible way.
I'd like to accomplish all the goals listed above with one single expression. So I would appreciate any suggestions ...
1
vote
1answer
103 views
A form builder component
I would love my component to be reviewed. I am looking forward to responses mainly answering the questions:
Is my code violating the SOLID principals? If so, where and how?
Does my component contain ...
1
vote
1answer
129 views
Reorganizing a PHP array structure (arrays within arrays)
I have this array within array which contains a lot of values:
...
4
votes
1answer
309 views
Reading XML files from RSS of different websites in PHP
I've created a working XML RSS reader. I wanted to know if it's a good one or not and if it's efficient for the server or not. I run this code every 12 hours or something give or take the amount of ...
2
votes
0answers
61 views
Nginx rewrite optimization for PHP execution
I've posted an excerpt from my Nginx configuration with the hope that someone can give me advice on anything I've done wrong or could do better. Please note that the below config works, but has been ...
2
votes
0answers
97 views
OOP Web scraper using regex to grab tag contents
I'm about learning about implementing the solid principle in PHP.
I want to create simple content crawler/grabber from some websites. This crawler will grab the content from the website url. Since we ...
4
votes
1answer
284 views
Database connection wrapper class
I am trying to create a PHP / MySQLi wrapper class that uses prepared statements, the goal of the class is to create a connection to the Database, then INSERT / <...