php

php 5 strpos() difference between returning 0 and false?

if(strpos("http://www.example.com","http://www.")==0){ // do work} I'd expect this to resolve as true, which it does. But what happens when I do if(strpos("abcdefghijklmnop","http://www.")==0){// do work} This also passes on php 5 because as far as I can work out the strpos returns false which translates as 0. Is this correct thin...

Not all fields are being saved in my MySQL Database.

My form class: <?php require_once ('Zend\Form.php'); class Sergio_Form_registrationform extends Zend_Form { public function init(){ /*********************USERNAME**********************/ $username = new Zend_Form_Element_Text('username'); $alnumValidator = new Zend_Validate_Alnum(); $username ...

Parse error on explode('-','foo-bar')[0] (for instance)

Why doesn't php support this syntax: $s = explode('-', 'foo-bar')[0]; ? ...

How can this routine be better optimized?

The routine below does two scans over an input stream of hypertext. The first pass is a spin replacement on user defined phrase options. The second pass is a find replace on the tags collection in the doReplace function below. I'm just looking for suggestions on how it might be optimized. I'm having no performance issues as is. But I wa...

const vs static in PHP

IN PHP5 i can declare a const value to a class: class config { const mailserver = 'mx.google.com'; } But i can also declare public static: class config { public static $mailserver = 'mx.google.com'; } In case of a config file which i will later us, like: imap_connect(config::$mailserver ... imap_connect(config::mailserve...

Facebook Application using PHP on server problem

Hi, I'm trying to wrtie a facebook application that generates random quotes using php. However, I'm getting this error and I don't know how to sort it. Parse error: syntax error, unexpected T_STRING in /home/a9607557/public_html/index.php on line 8 This is the code I have: <?php require_once 'includes/facebook.php'; $appapikey = '<Ha...

PHP: Check if file is loaded directly instead of including?

Hello Is there a way to prevent user viewing an file but still use it as included to another file in php? Hope you understood! Martti ...

hosting a java based server

i want to write a game that will utilize java applets as client programs and will run a server application to operate the game (control the game handle the chat etc) is there a way to host such an application on a free server, or does it require a specialized server? also is there a way to use php for tcp connection so it will receive th...

how read data from file and execute to MYSQL?

i create form to load sql file and used fopen function top open file and read this but when want to execute this data to database not work? what is wrong in my code????????????? $ofile = trim(basename($_FILES['sqlfile']['name'])); $path = "sqlfiles/".$ofile; //$data = settype($data,"string"); $file = ""; $connect = mysql_connect...

PHP: ignore_user_abort(true) in all scripts

I have a website which works with PHP on the server side. Users access pages and PHP does some calculations, writes data to a MySQL database etc. Imagine a user accesses a page where PHP creates an account for the user. The creation consists of two parts: inserting the registration data into the table "users" and inserting settings for...

Usage of ||, OR in PHP

I have the following code which redirect pages depends on $path. ... $path = $this->uri->segment(3); $pathid = $this->uri->segment(4); if($path=='forsiden'){ redirect('','refresh'); }elseif($path =='contact'){ redirect('welcome/kontakt','refresh'); }elseif($path =='illustration'){ $thi...

Firefox/chrome is not displying uploaded image but IE6 is displaying in php why so

HI Everybody I am uploading an user image while he/she sign up and then in his/her home page i have given a link if he/she want to show his/her uploaded image.There is no problem .. But when i try to see this image through firefox/chrome my image is not displaying only a tiny icon is displaying there.Image is jpeg type But when i am t...

how to store multile images full path into database so that i can display them in user home page like orkut .Give me idea..

I am making an application in which every user have to sign in first and then he can access his home page.Now on home page i have given a option of uploading image.Now if user is uploading one image i am storing the full path of uploaded image into database and from there i can display image easily by img tag... But what should i do whe...

Best practice to make Config object available inside Controller and Model

Hello, On application start I'm creating Config object (Singleton). How could I make Config object be available inside Model and Controller? Should I pass Config object to constructor as method parametr or I should better use $this->config = Config::getInstance()? Any other methods? Thank you ...

How to store image into binary form and how to retrive that back?

The best way to store images into MySQL is by storing the image location as a charater string. If you need to manipulate the image, then, the best way is to copy the image as a binary. How one can store images into binary form and how we can retrive them back? I don’t know anything about this technique. Please tell me how we can do thi...

What function do you use for building URLs?

Hello, For example, your application is using this way for passing vars into your application example.com/controller/method/var_1/var_1_value.var_2/var_2_value/ etc. I think it will be really useful to create function for creating such URLs from arrays Input array( 'controller' => 'controller' 'method' => 'controller_method', 'var_...

Any reason PHP don't iterate array by reference?

$arr = array(array(array())); foreach($arr as $subarr) { $subarr[] = 1; } var_dump($arr); Output: array(1) { [0]=> array(1) { [0]=> array(0) { } } } But for object,it's reference: class testclass { } $arr = array(new testclass()); foreach($arr as $subarr) { $subarr->new = 1; } var_dump($arr); Output: array(1...

Why won't my global variables properly resolve?

here is my plugin activation code $classified_category_name = 'classified'; $credit_table_name = 'credits'; $credit_table_version = 0.1; register_activation_hook(__FILE__, 'LBH_Classifieds_Activate'); function LBH_Classifieds_Activate() { global $wpdb; global $classified_category_name; global $credit_table_name; global...

Escape string value for plist with php

How can I escape a string containing random characters with php for a plist file? htmlentities() seems doesn't seem to be strict enough. For example: <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; <plist version="1.0"> <string><?php echo...

How do I check if a RSS feed is working?

For example, if there is an RSS feed and for some reason it is down or cannot be grabbed I want to display a simple message saying "feed cannot be grabbed". Right now PHP spits out a really ugly warning message. note:I do not need to know whether it is valid. I just need to know if the feed actually works. I do not want to turn off war...