Skip to main content

PHP

Replace \r\n with <br />
Replace \r\n with <br />
You wouldn't think was so hard, but I often come across this when processing textarea input in a contact form, into the email to the client.... A long story cut short... the solution I found was below: $msg = '<p>Address: <br />'.str_ireplace(array("\r\n",'\r\n'),'<br />', $...
Replace in MySQL
Replace in MySQL
A quick example of a SQL statement with REPLACE $query = 'SELECT id FROM `user` WHERE email ="'.$email.'" AND REPLACE(tel_1, " ","") = "'.$phone.'" LIMIT 1';
Convert Database Date to Something More 'User Friendly'
Convert Database Date to Something More 'User Friendly'
// // Convert database date to something more user friendly // function userFriendlyDbDate($date){ $time = strtotime($date); return date('d/m/Y H:i', $time); }... and the other way round, so converts to database date format... // // Convert date to database date format // function...
PHP Email Validation
PHP Email Validation
Email validation is something that is needed in a variety of situations, but I’ve always struggled to find a good one…. Well, here are 2! The first is something I found online somewhere, and has been modified a little… $email = 'you@youremailaddress.com'; if(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9...
PHP Logout
PHP Logout
A good logout script is needed in most applications, and here’s the one I use. I have this script in a ‘config’ file that I call at the beginning of every file in the site, so you can logout from any page… if(isset($_GET['logout'])){ // trigger if ?logout is in the url $_SESSION = array(); if(...
SELECT inside a SELECT
SELECT inside a SELECT
I often forget the exact syntax of things like this… So here’s an example… $query1 = 'SELECT * FROM `'.$dbName.'`.`users` WHERE email NOT IN (SELECT email FROM `'.$setupDBName.'`.`users`)';From Mark Jackson Also the ‘IN’ and ‘NOT IN’ can be used to specify multiple conditional values – for example...
#1054 – Unknown column in 'where clause'
#1054 – Unknown column in 'where clause'
The following SQL query causes an error SELECT vote_vo_ip, COUNT(*) as times FROM `vote` LEFT OUTER JOIN `voter` ON vote.vote_vo_id = voter.vo_id WHERE vote_co_id = 2 AND times > 1 GROUP BY vote_vo_ipThe column ‘times’ has not been created when we run the WHERE clause, so we have to use HAVING...
Warning: Cannot modify header information
Warning: Cannot modify header information – headers already sent by
If you get a PHP error ‘Warning: Cannot modify header information – headers already sent by‘ it’s normally down to whitespace before or after the PHP start or stop tags. For example a gap before <?phpwill do it… If in my case, I’ve just put a ‘tried and tested’ script onto a different server,...
Export to CSV file
Export to CSV file
This is something you’re likely to do several times in several different scenarios. The common one for me is generating reports from a database. I tend to build a $_SESSION array as I run the SQL query that is displayed on the page, and then provide a link to ‘Download CSV’. Then the csv-export...
Another escape data function
Another escape data function
As the title says // create a function called for escaping data function escape_data($data){ $data = ereg_replace("[^A-Za-z0-9]", "",$data); $data = str_replace('\\','',$data); $data = strtolower($data); $data = mysql_escape_string(trim($data)); return $data; }

Pages

  • 1
  • 2
  • 3
  • 4
  • next ›
  • last »
 
 
Jon Moore

Search form

Jon Moore

Tips 'n' Snips

 
  • Home
  • General
  • Drupal
    • Drupal 6
    • Drupal 7
    • Module Building
  • HTML & CSS
  • Javascript
  • jQuery
  • PHP
    • CodeIgniter
    • Handy Functions
    • MySQL
  • WordPress
  • About

BBC Technology News

  • Kashmir users kicked off WhatsApp
  • Heavy fine for Chinese firm over unlicensed game
  • Uber had 6,000 US sexual assault reports in two years
  • Electric eel lights up Christmas tree and other news
  • Rory Cellan-Jones: Reporting the news with Parkinson's
More

Sitepoint

  • The Real Future of Remote Work is Asynchronous
  • 7 Ways Developers Can Contribute to Climate Action
  • How to Divert Traffic Using IP2Location in a Next.js Website
  • 10 Zsh Tips & Tricks: Configuration, Customization & Usage
  • Building a Habit Tracker with Prisma, Chakra UI, and React
More

Heart Internet

  • Sponsor Neil Hunter’s amazing Antarctic expedition – for Diabetes UK
  • 15 web design books of 2019 that you should read
  • 12 podcasts for every creative person’s commute
  • Ten TED Talks every designer and web creative should watch before 2019 is over
  • The rise of the robots: Will AI take over graphic design?
More
 

Backend Coders

  • PHP
  • Handy PHP Functions
  • PHP MySQL

Frontend Coders

  • HTML & CSS
  • jQuery
  • Javascript

CMS/CMF Systems

  • Drupal
  • Drupal 6 Specific
  • Drupal 7 Specific
  • Drupal Module Building
  • WordPress

About

  • Home
  • About
 

© Jon Moore 2019

All stock images are from www.istockphoto.com