Skip to content

Tag: php

how to check if PHP variable contains non-numbers?

I just want to know the method to check a PHP variable for any non-numbers and if it also detects spaces between characters? Need to make sure nothing weird gets put into my form fields. Thanks in advance. Answer If you mean that you only want a value to contain digits then you can use ctype_digit().

Using an array as needles in strpos

How do you use the strpos for an array of needles when searching a string? For example: $find_letters = array(‘a’, ‘c’, ‘d’); $string = ‘abcdefg’; if(strpos($string, $find_letters) !== false) { …

How can I divide a date range by number of months?

My dilemma is that if I request more than 6 months or so ( I do not know the approximate number ) from my webservices ( which gets called via JS ), I get nothing back. In other words, I have to limit it to 6 months. So let’s consider this scenario: I need to split this up by 6

PHP – Checking for return false;

Just a quick question – and I’m sure really basic! I have the following code: On the other end of this I am currently doing Is writing the following the same? Which method is the preferred method if both are correct? Thanks 🙂 Answer The triple-equal operator is type-sensitive. So when you check: &…

How to minify php page html output?

I am looking for a php script or class that can minify my php page html output like google page speed does. How can I do this? Answer CSS and Javascript Consider the following link to minify Javascript/CSS files: https://github.com/mrclay/minify HTML Tell Apache to deliver HTML with GZip – this generall…

PHP loop through months array

This should be easy but I’m having trouble… In PHP how can I echo out a select drop down box that defaults to the current month and has options for 8 months prior (even if it goes in the last year). For example, for this month it would default to June and end at November. Answer Alternative for &#…

Can’t delete php set cookie

I’ve set a cookie through this call in php setcookie(‘alert_msg’, ‘you have the add badge’); I have tried unsetting it this way setcookie(‘alert_msg’, ”); setcookie(‘alert_msg’, false); setcookie(‘…

Restriction based on IP ranges

I am building an admin panel. and I want to block certain IP ranges. I’m testing this on my localhost wamp server but ir doesn’t seem to redirect me. Any input is appreciated. Answer Is sufficient to use string comparison Update: Taken from the comments of inits answer Suppose i want to block any …