I have the following array: I’d like to rotate the elements of this array with the first key being the tomorrow. Let’s say today was Wednesday, I’d want my array to look like this: I already have the weekday available (e.g. a string ‘thursday’). It gets passed into the function t…
Get category tree recursively (Yii)
I have a table with following structure: categories id name parent_id I want to get the tree of categories with single function. I’ve written something like this in my model, but it doesn’t work. Can someone help me with this? Thanks. Answer I’ve finally solved the issue. If someone interest…
Parse error: Syntax error, unexpected end of file in my PHP code
I got an error: With this code: What’s the problem? Answer You should avoid this (at the end of your code): and this: You shouldn’t put brackets directly close to the open/close php tag, but separate it with a space: also avoid <? and use <?php
How can I get parameters from a URL string?
I have an HTML form field $_POST[“url”], having some URL strings as the value. Example values are: https://example.com/test/1234?email=xyz@test.com https://example.com/test/1234?basic=2&email=xyz2@test.com https://example.com/test/1234?email=xyz3@test.com https://example.com/test/1234?email=xy…
Find and replace emails and phone numbers in PHP
I was hoping for a little help on this, as it’s confusing me a little… I run a website that allows users to send messages back and forth, but on the inbox i need to hide both emails and phone numbers. Example: This is how a sample email would look like. Hi, my phone is +44 5555555 and email is
Why is base64_encode() adding a slash “/” in the result?
I am encoding the URL suffix of my application: $url = ‘subjects?_d=1’; echo base64_encode($url); // Outputs c3ViamVjdHM/X2Q9MQ== Notice the slash before ‘X2’. Why is this happening? I thought …
Send multiple elements with jQuery POST
I have this jQuery code to add elements in a table row with an “add” button: $(“#add”).click(function() { $(‘#selected > tbody:last’).append(‘
<select id='…
How to reduce the image size without losing quality in PHP [closed]
I am trying to develop an image-based web site. I am really confused about the best image type for faster page loading speeds and best compression practices. Please advise me on the best way to …
Doctrine 2: Load entity and childs count
I have these two entities: Message entity class Message { /** * @ManyToOne(targetEntity=”User”) * @JoinColumn(name=”author”, referencedColumnName=”id_user”) */ protected $author; …
Add ‘x’ number of hours to date
I currently have php returning the current date/time like so: What I’d like to do is have a new variable $new_time equal $now + $hours, where $hours is a number of hours ranging from 24 to 800. Any suggestions? Answer You may use something like the strtotime() function to add something to the current ti…