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’); …
Tag: php
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…
Php, in_array, 0 value
I was trying to understand the in_array behavior at the next scenario: $arr = array(2 => ‘Bye’, 52, 77, 3 => ‘Hey’); var_dump(in_array(0, $arr)); The returned value of the in_array() is …
Default value of Doctrine ORM association
I have the entity (such as below). I want to set some default values while creating. As you can see in __construct, it is easy to set the $name (string), but how can I set the $group? (for example I …
Undefined function mysql_connect()
I have ran aptitude install php5-mysql (and restarted MySQL/Apache 2), but I am still getting this error: Fatal error: Call to undefined function mysql_connect() in /home/validate.php on line 21 phpinfo() says the /etc/php5/apache2/conf.d/pdo_mysql.ini file has been parsed. Answer Well, this is your chance! I…
Can cookie values be set after html has loaded on a page?
I read that cookie values can be set after HTML content has been sent from a PHP script to the web server. However, when working with this, I have not been able to set the cookies as I had hoped. Can someone straighten out my discrepancy? Answer PHP can only set cookies while sending the headers of the page (…
Create a DSN for the function odbc_connect for Oracle
The information I have concerning the Oracle database O need to connect to using PHP through EasyPHP is the following: user, password, host, port, service. I’m new to ODBC. I tried to use the function odbc_connect, but I keep getting errors simply because I don’t know how to make a DSN. I tried us…
Finding closest larger resolution with nearest aspect ratio in an array of resolutions
I have an array: I want to retrieve closest larger value with the nearest aspect ratio (same orientation). So, in case of $needle = ‘768×1280’ – 800×1280. And, in case of $needle = ‘320×240’ – 640×480. While the closest here is 480×640 it shouldn…