Skip to content

Tag: php

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

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…

How to run composer from anywhere?

I have just installed composer in my /usr/bin folder, so when from that folder I run php composer.phar I get the help info about composer. But, when I try to run the same from other folder I get Could not open input file: composer.phar. How to call php composer.phar from every where without problems? Answer c…

Return One Row from MySQL

Amateur question, but something I’ve been wondering about. What is the PHP for selecting one row from a MySQL query? AKA you’re picking something by unique ID (you know there’s only one row that matches your request) and want to get only that value. Do you still have to use a while loop and …

How to Check if value exists in a MySQL database

Suppose I have this table: I want to check if the value c7 exists under the variable city or not. If it does, I will do something. If it doesn’t, I will do something else. Answer preferred way, using MySQLi extension (supported from PHP 5 onwards): deprecated and not supported in PHP 7 or newer:

How to make files not shareable?

I am developing a website with php that is about uploading and selling/buying pdf documents. Of course, I need to program it in a way that makes it impossible (or at least very hard) to copy the purchased documents. Do you know of any mechanism to do this? Is it a programming issue or rather a pdf issue? Also…

Simulating a command shell output in a web browser

BACKGROUND: Right now, in our company we have a PHP based app to automate our report building. It works like this: A webpage with a form generates a ini file with some configurations that is saved localy a PHP CLI script accepts the ini file generated on step 1 and based on it, creates a directory with docume…