Skip to content

Get the index of a certain value in an array in PHP

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…

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 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…

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