php

Simple way to check an array for "holes" in the keys

I have a simple associative array: $ar = array( 1=>'foo', 2=>'bar', 5=>'foobar', 8=>'barfoo' ) I need to efficiently find holes in the keys. The keys are guaranteed to be integers. findHole($ar) > 0 findHole($ar,1) > 3 findHole($ar,5) > 6 what is the easiest way to do this? ...

PHP, SPL predefined constants

where can i get some references about SPL predefined constants like SELF_FIRST,CHILD_FIRST ? on php.net i don't get much(just their type). ...

Using preg_replace

How would I replace all span tags (and whatevers inside them) that have the class pagenum pncolor with an empty line. str_replace wouldn't work because the name is different for all of them, so I assume I'd use preg_replace, but I'm sure how that works. <span class='pagenum pncolor'><a id='page_001' name='page_001'></a>001</span> <p>Som...

PHP - move_uploaded_file doesn't work for music/video

Hey, I'm working on a upload script and using move_uploaded_file() function. The problem is, that it only works for .txt, .jpg, .psd and some other file types I've tryed, but not for .mp3, .mov, .avi and maybe others. There is nothing to the script, it's just the function. An interesting thing is, that it doesn't show any error msgs, i...

Why is foreach so slow?

PHPBench.com runs quick benchmark scripts on each pageload. On the foreach test, when I load it, foreach takes anywhere from 4 to 10 times as long to run than the third example. Why is it that a native language construct is apparently slower than performing the logic oneself? ...

Reading php generated XML in flash?

Here is part 1 of our problem (Loading a dynamically generated XML file as PHP in Flash). Now we were able to get Flash to read the XML file, but we can only see the Flash render correctly when tested(test movie) from the actual Flash program. However, when we upload our files online to preview the Flash does not render correctly, missi...

Web service API - which language is better?

Hi, I wrote a web service API which services REST requests in php. It didn't take much time to actually setup this on apache. But, I am more comfortable writing python code rather than php code. Can python be used as a server-side scripting language like php? What changes are necessary to make it work with apache? Thanks Bala Mudiam ...

How to create new object using classname stored in variable and how to pass another variable into this class's constructor?

Hello, I have classname stored in variable $classname; also I have an array of values I should pass into object constructor. $classname = "MyClass"; $variables = array(1, 2, 3, 4); I need $objInstance = new MyClass(1, 2, 3, 4); How? Thank you. ...

AJAX form submission

The following code does not submit the input values: $('.button').live('click', function() { var date = $('#date', this).val(); var guests = $('#guests', this).val(); $('.resLoad').load('/confirmation.php?guests='+guests+'&date='+date); }); It loads the page in the proper div, but the variables are listed as ...

PHP6: Is short_open_tag removed or deprecated or neither?

For instance magic_quotes_gpc has been deprecated as of PHP 5.3 but will not be removed until PHP6. In PHP6 is short_open_tag set to be removed or deprecated or neither? Whether it's appropriate to use short_open_tag has already been debated ad nauseam - I'm really interested in the the official stance of the PHP core developers. The PH...

How to create uniqe key value in PHP?

How do I create unique key value in PHP? I need simple unique keys with a length of 20 digits (not more than 33). ...

Article Thubmnail Suggestion

Hi ...., I've observe some webiste tutorial in the internet. I found, while some article post, there is a thumbnail in the article list. I wanna build, CMS like that. So I need suggestion how to implement adding thumbnail while we want to post our. In my mind, In the post form, I put file input. and after the post action, I create page...

XPath Invalid Expression

<?php $feed = file_get_contents('http://thexmofo.wordpress.com/feed/'); $xml = new SimpleXMLElement($feed); $xml->registerXPathNamespace('media', 'http://thexmofo.wordpress.com/feed/'); $images = $xml->xpath('/rss/channel/item/media:content@url'); var_dump($images); ?> Can anyone tell my why I'm getting Warning: SimpleXMLElem...

I am learning about static variables but the script below doesn't quite work help!

function do_something() { static first_time = true; if (first_time) { // Execute this code only the first time the function is ➥called ... } // Execute the function's main logic every time the function is ➥called ... } it's bring up this error Parse error: parse error, expecting `T_VARIABLE' in C:\wamp\www\functions.php on line 3 ...

PHP equivalent of Python's __name__ == "__main__"?

As per the title, is there PHP equivalent of __name__ == "__main__"? Is there something that would work for both scripts executed through the command line and through a web request, or would a custom function be needed? For those unfamiliar with Python, __name__ == "__main__" allows you to define a module file, and also have some thing...

Acessing weblogs from apache webserver

Hi peeps, As i'm new to php and apache web programming, i am a bit confuse of how to get access to the weblogs from the server.. i am currently doing a project on adaptive websites and i need to get hold of the weblogs to create adaptation of the website. i actually want to gain access where i will be able to store it in a data base. c...

How to encrypt data in javascript and decrypt in php?

Is there any javascript function that can encrypt data: For example i want to use encrypted data in my URL passed by ajax GET request, http://sample.com/mypage/TDjsavbuydksabjcbhgy where TDjsavbuydksabjcbhgy an encrypted data equivalent to 12345. Now i want to retrieve that data in PHP by decrypting it, so that i can use the 12345. I...

SOAP error for php

Hi, I'm using http://www.php.net/manual/en/book.soap.php and I'm getting this error "Method Not Allowed" $wsdl_url = "http://192.168.100.165:9080/service/service?wsdl"; $client = new SoapClient($wsdl_url); $userName = "hello"; $password = "testing"; $test = "OK"; $login = $client->ClientOperation(array("userName"=>$userName, ...

position in an array

how could i find out that twoVal is at postion 1? $arr = array('Cool Viski' => array('oneVal' => '169304', 'twoVal' => '166678', 'threeVal' => '45134')); ...

How to make returned from PHP Data fill MXML Flex mx:List (Using actionscript and PHP)

I am Using Flex 3 and apache with PHP 5.2. I am searching for simple as possible way to fill my mx:List with data using POST URLRequest. In Flex builder I am using the next code public var variables_se:URLVariables = new URLVariables(); public var varSend_se:URLRequest = new URLRequest("DataProvider.php"); public var varLoader_se:URLL...