Why use PHP OOP over basic functions and when?

There are some posts about this matter, but I didn't clearly get when to use object-oriented coding and when to use programmatic functions in an include. Somebody also mentioned to me that OOP is very heavy to run, and makes more workload. Is this right?Let's say I have a big file with 50 functions. Why will I want to call these in a class? And not by function_name()? Should I switch and create an object which holds all of my functions? What will be the advantage or specific difference? What benefits does it bring to code OOP in PHP? Modularity...Read more

php - PHPMailer with Outlook365 - imap_append 7KB size limit

I have PHPMailer setup to use our Outlook365 server to send emails with attachments. It works great until the script, using imap_append, attempts to add the message to our "sent" folder. What I have discovered is that if the attachment is more than 7KB in size, it fails. Less than 7KB, it works. The recipient receives the attachment either way.Any idea where this limitation is coming from and how I can increase it? Here's the code block for saving the messages to the sent folder. function save_mail($mail) {global $config;$MailHost = "{".$confi...Read more

php - Combine two elements in XML file

First off thanks for any help!I have an xml that looks like this:<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE tv SYSTEM "xmltv.dtd"><tv source-info-url="http://tvschedule.zap2it.com/" source-info-name="zap2it.com" generator-info-name="zap2xml" generator-info-url="zap2xml@gmail.com"><channel id="I16689330.labs.zap2it.com"> <display-name>502 WCBSDT</display-name> <display-name>502</display-name> <display-name>WCBSDT</display-name> <icon src="https://zap2it.tmsimg.c...Read more

Selecting a letter from random group of array for registered user in php

The problem is I have two groups say A and B which I have predefined in an array like $random_groups = [B,A,A,B,A,A,B,B,A,A,B,B,B,A,A,B,A,B,B,A,A,A,B,B,A,B,B,B,A,A,A,B,B,A,B,A,A,B,B,B,A,A,A,B,B,A,A,B,A,B,A,B,B,A,B,A,B,A,A,B,B,A,B,A,B,A,B,A,A,B,A,B,B,B,A,A,B,A,B,A...]and when user submits a form he should get B from the above array if he is the first person to register after I apply this logic and if second person registers he should get A, if third he should get A and so on.I am so confused to have to work around this logic. I tried a few optio...Read more

php - How to get specific value from EntityType Field in Symfony 2.8

I am new in Symfony and try to creating a simple form in Symfony and try to get the value from Database through EntityType Field but I can't get the value when I dump the submitted form data it shows object of EntityType Field. my codepublic function indexAction(Request $request){ // user details if($this->getUser()){ $user = $this->getUser()->getId(); } else { $user = ''; } $classarray = array( 'School 1' => 1, 'School 2' => 2, 'School 3' => 3, ); // create a class booking form ...Read more

How can I display HTML-Code with PHP?

I have a Login and I want to display a class if someone keeps a field empty. The if-part works good. By pressing on the button, the user shell stay at that page and then the error-class shell appear at the top just like here: http://www.loltyler1.com/contactThe class/HTML-code that i want to display:<div class="empty">Please don't leave any field empty!</div>The PHP-code:if (empty($username) || empty($password)){ echo("<script>window.location = '../login.php?login=empty';</script>"); echo '<div class="empty"&g...Read more

Move multiple array columns PHP

I'm writing a small script which will split one column into three from .csv file. The csv file has an array with 18 columns, I need to split 5th one and insert the data into [6][7][8], how can I move everything whats [6]-[18] to [9]-[21] so my data won't be overwritten?...Read more

PHP random string generator

I'm trying to create a randomized string in PHP, and I get absolutely no output with this:<?phpfunction RandomString(){ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randstring = ''; for ($i = 0; $i < 10; $i++) { $randstring = $characters[rand(0, strlen($characters))]; } return $randstring;}RandomString();echo $randstring;What am I doing wrong?...Read more

PHP array delete by value (not key)

I have a PHP array as follows:$messages = [312, 401, 1599, 3, ...];I want to delete the element containing the value $del_val (for example, $del_val=401), but I don't know its key. This might help: each value can only be there once.I'm looking for the simplest function to perform this task please....Read more

arrays - How do I use php to access a data point within xml output coming from a url?

I am trying to access a single data point from the XML below. My goal would then be to insert into an html table. The following code has been giving me a stdClass Object and I can't figure out how to grab a single data point.Here is the XML:<?xml version="1.0" encoding="utf-8"?><response> <status> <code>0</code> <message>OK</message> </status> <data _idtype="ticker" _id="QYLD" _MstarId="F00000QEMN" _CurrencyId="CU$$$$$USD"> <api _id="z87pq63qh3gbhraf"> <TS-DayEndTra...Read more

php - Undefined variable: total still getting error after $total = 0;

I'm getting this problem in PHP, when im getting the median and mean, but when the program reaches the mode it displays the error: Undefined variable: total.I tried declaring $total = 0; at the beginning of the function but it doesn't solve the problem.this is my code:<?php$number = ($_POST["name"]);function mmmr($number, $output = \'mean\.'){$total = 0;if(!is_array($number)){ return FALSE;}else{ switch($output){ case \'mean\.': $count = count($number); $sum = array_sum($number); $total = $sum, $...Read more

php - Random multiplication table generator

im creating an multiplication table system in PHP.The input tho this system is an table number and the amount of questions. The table 1 is skipped so 2 to input table At this point I just fill an array like this: $nCount = $_POST['count'];$nHighest = $_POST['table'];$aSums = [];$nCounter = 0;while($nCount > 0){ $cSumString = rand(2, $nHighest) . "*" . rand(1, 10); $aSums[$nCounter] = $cSumString $nCount--; $nCounter++;}I want to parse the questions in multiple ways:3 * 5 = ... (normal)... * 5 = 25 (first number to fill in)8 * ......Read more

php - what happens to a cron if its not complete and next iteration is due

I know I am asking something and not code related issue but before implementing my cron I wanted to ensure that I know what to expect from the execution.I have a cron that delivers 125 emails every 2 minutes and I wanted to know if something happens and the cron is not complete by the time the next iteration is due.sending an average of 125 emails every 2 minutes is very important and I would prefer a solution which will ensure that backlog is cleared whenever possible.Any advise is highly appreciated....Read more

php - How to assign session variable directly from html tag?

I am trying to set $_SESSION variable directly into tag but it doesn't work. Below is my tag<td><a href="persons.php?name='.$row['name'].'"> '.$row['name'].'</a></td>Can I do something like<td><a href="persons.php?name= $_SESSION['test'] ='.$row['name'].'"> '.$row['name'].'</a></td>I have also tried doing <?php session_start(); $_SESSION['name'] = ".$row['name'].";and then passing the $_SESSION['name'] into tag but I am doing it wrong. <?php session_start...Read more