I have an array: I want to get the index for a given value (i.e. 1 for string2 and 2 for string3) All I want is the position of the strings in the array string1 is 0 string2 is 1 string3 is 2 How to achieve this? Answer array_search is the way to do it. array_search ( mixed $needle ,
Sanitize user-supplied URL for file_get_contents
I want to use file_get_contents to implement a proxy so I can do cross domain AJAX requests. Query string will be used to supply the URL to file_get_contents. Now the problem is people can muck around with the query string in order to read local files on the server. I don’t want this. Can someone get me…
can I have multiline text with GD and PHP?
I’m trying to output multiline text with GD+PHP but can’t get it working. my php knowledge is really basic. here’s the code, any idea on how to output 2 or 3 lines of text? $theText = (isset($_GET[‘…
Is it possible to remove a Password from a PDF file using PHP?
I would like to ask if it’s possible to use PHP in removing a password from a password-protected PDF file in which I already know the password? I’ve seen this page which provides many options but using bash script. 🙁 I was required to use PHP as much as possible. Any suggestions appreciated! Answe…
Sending POST data in Android
I’m experienced with PHP, JavaScript and a lot of other scripting languages, but I don’t have a lot of experience with Java or Android. I’m looking for a way to send POST data to a PHP script and …
How to add a new method to a php object on the fly?
How do I add a new method to an object “on the fly”? $me= new stdClass; $me->doSomething=function () { echo ‘I’ve done something’; }; $me->doSomething(); //Fatal error: Call to …
How do I convert output of number_format back to numbers in PHP?
PHP can’t recognize 1,200.00(generated by number_format) but only 1200.00, What’s the general solution for this problem? Answer You could remove any character that is not a digit or a decimal point and parse that with floatval: And if the number has not . as decimal point:
PHP Store User Data without Sessions
Is there anyway to store users data such as userid, email, etc to be accessible from all pages of a website after they have logged in, but without using sessions or cookies? For example: after they login at login.php now, how do I access $currentUser from another page, such as index.php if I shouldn’t u…
Convert a series of parent-child relationships into a hierarchical tree?
I have a bunch of name-parentname pairs, that I’d like to turn into as few heirarchical tree structures as possible. So for example, these could be the pairings: Which needs to be transformed into (a) heirarchical tree(s): The end result that I want is a nested set of <ul> elements, with each <…
How add class=’active’ to html menu with php
I want to put my html navigation in a separate php file so when I need to edit it, I only have to edit it once. The problem starts when I want to add the class active to the active page. I’ve got three pages and one common file. common.php : index.php : All three pages are identical except their