I have an array with filenames. I want to check if the array have a file with extension ‘.txt’. How can I do that? in_array only checks for a specific value. Answer Contrarily to other answers suggesting array_filter, I don’t return something. I just check if it exists in the array. Besides,…
Remove double quote in json_encode()
I want remove double quote in my json_encode, that is my code: My result is that: I want to remove double quote of “id_posiciones” and “device_version” too. How can I do for the result is that: Answer If you add an underscore to your regex at the end it will do it. I assume that’…
How to read a CSV file using PHP and display content in Table/DIV?
I am using the following PHP code to read a CSV file with two column (e.g. x,y) and display the content in a table:
Is there a technique for avoiding rewriting long operands in if statements?
I find myself constantly writing if statements like the following: if(isset($this->request->data[‘Parent’][‘child’])){ $new_var[‘child’] = $this->request->data[‘Parent’][‘child’]; } …
Hidden Input Values not being passed through form to New URL
I have a small html file working in the frame of a website. It currently requests a zip code and then calls a php page to query the database. The iframe gets the id number from the parent page and then gets the zip code from its own page. Here is the code snippet. However, When I enter the zip
Generating Password Hash In PHP 5.5 And Setting Cost Option
I know PHP 5.5 is in alpha but this class I am making is just being made in advance to utilize it’s hashing feature by using function_exists(). I checked out the password_hash documentation. The 3rd argument is for $options which currently supports two options, ‘salt’ and ‘cost’.…
Get currency symbol in PHP
Let’s start with simple piece of code to format money with NumberFormatter: $formatter = new NumberFormatter(‘en_US’, NumberFormatter::CURRENCY); echo $formatter->formatCurrency(123456789, ‘JPY’); …
PHP: How to detect direct requests of external visitors?
I would like to detect/prevent/forward direct requests of external visitors. Some scripts should only be displayed in a jQuery dialog. My current code: $(“.dialog”).click(function() {…
MySQL error with Not unique table/alias with join
SELECT `idstudii` FROM (`studii`) JOIN `studii` ON `mesaje`.`idstudii`=`studii`.`id` JOIN `users` ON `users`.`id`=`studii`.`idusers` WHERE `studii`.`idusers` = ‘1’ I have this sql query which …
Doctrine – Add default time stamp to entity like NOW()
Following the Doctrine guidelines I understand how to set a default value for an Entity, but what if I wanted a date/time stamp? http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/faq.html My problem is my database has a default of NOW() on a field but when I use Doctrine to insert a reco…