Questions tagged [php5]

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.

Filter by
Sorted by
Tagged with
-1
votes
0answers
11 views

PHP PDO Uploading Image to Database & directory Template so far [on hold]

I have written out the following code to upload image files to a directory called Uploads on my website server, the image upload part is working and has been tested(So this is working code). But I ...
1
vote
0answers
21 views

Salary-structure report using a web-presentation

I had to create a report which presents the salary structure of a firm. The data needed was provided by the client as CSV-files. I used PHP for the reading and preprocessing of the data. The actual ...
1
vote
2answers
54 views

Validate array elements in PHP

$elements is an array, which may contain 'x' or 'y' keys, I want to check if they exist, otherwise assign a 0. I'm looking for a clean way to validate it. I'm new ...
3
votes
0answers
27 views

Use a pattern for fields validation

I need to validate the fields of user sent by an API. All works fine but the only one problem is that I don't like the solution is not an OOP solution. In the controller I call the service created by ...
1
vote
1answer
42 views

Merging and summing multi-dimensional arrays

I've found myself today really struggling with this subject and I'm pretty sure that there must be a better way to do this. First of all my arrays have the same layout, I need to merge them and sum ...
2
votes
2answers
211 views

Users management php class

After a little bit of troubleshoots, I've finished this simple users registration and login class. It uses PDO to connect to a mysql database, I've tried also to ...
1
vote
1answer
87 views

Appending objects to an array based on a field

I am working with PHP5 (Laravel 5.1), and I couldn't optimize my function, which takes more 4 minutes turning, and fails in the end when I have a huge data (around 6500 rows, but working when i test ...
0
votes
1answer
31 views

Quiz setting users grade

I have made this code to determine the users grade for a quiz. However I've just been thinking that maybe I could shorten the code somehow? as its just a lot of if and elif statements. ...
1
vote
1answer
50 views

Git Autoupdater

At my office we have an internal monitoring tool we use on customer systems to monitor various vitals and notify us via Slack. Our Lead Dev and Chief Architect are very paranoid about Git, and ...
-1
votes
1answer
32 views

PHP return validate method of if one error is found

My method counts the number of times an error occurs. I have a feeling my snippet isn't the best practice way of doing this. So when one of the validation methods fails I want to stop the method. <...
0
votes
2answers
1k views

Sync Server Time with User's Timezone

I have a web application which is being used by users from different parts of the world. In order for users of the site, to be able to view the timestamps in their local time, I've a settings page set ...
2
votes
1answer
110 views

Function to insert a tag into a database

I'm developing a MVC structured RESTful API project (thanks to the help of Mārtiņš Tereško for explaining it). Almost all of my functions look similar to this: ...
0
votes
1answer
99 views

Populate two arrays with two different SQL queries

I am using Joomla and connecting to an MSSQL database to store the resulting set(s) in arrays. I am utilizing this syntax, but there must be a more efficient way of coding this. ...
3
votes
4answers
4k views

Which is cleaner: a constructor with many parameters or many setters after construction? [closed]

I'm trying to work out which is cleaner, having a large constructor or having to use many setters on a new object before doing some work with it. Large constructor: ...
4
votes
1answer
981 views

Code for a Person DTO, with tests

My needs are to manage DTO in a php5.3 application. I've written few lines of code in TDD with phpunit 6. The scenario I want to implement is a request with following fields: name surname password ...
1
vote
1answer
105 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: ...
3
votes
2answers
304 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 ...
2
votes
1answer
113 views

Retrieving a message from a cryptocurrency daemon

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 ...
1
vote
1answer
2k 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
577 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
4k 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 ...
1
vote
2answers
2k 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
131 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: ...
2
votes
1answer
599 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 ...
2
votes
1answer
178 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
958 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 ...
2
votes
2answers
330 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
99 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
1k 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. ...
1
vote
2answers
1k 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. ...
1
vote
2answers
410 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
2k 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
104 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
128 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
384 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
219 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
70 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
266 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
61 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
1k 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. config.php: ...
1
vote
1answer
42 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
3k 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
98 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
268 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
100 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
73 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: ...
2
votes
3answers
4k 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
487 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
62 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
591 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 ...