Should caught exceptions be re-thrown directly, or should they be wrapped around a new exception? That is, should I do this: or this: If your answer is to throw directly please suggest the use of exception chaining, I am not able to understand a real world scenario where we use exception chaining. Answer You …
Running php script (php function) in linux bash
How we run php script using Linux bash? php file test.php test.php contains: Answer From the command line, enter this: Make sure that filename.php both includes and executes the function you want to test. Anything you echo out will appear in the console, including errors. Be wary that often the php.ini for Ap…
Install PECL on Mac OS X 10.6
Is there any way to install PHP:s PECL handler on Mac OS X 10.6, to be used with the bundled PHP?
php regex number and + sign only
I need a php function to validate a string so it only can contains number and plus (+) sign at the front. Example: +632444747 will return true 632444747 will return true 632444747+ will return false …
Regular expression for a string that must contain minimum 14 characters, where at minimum 2 are numbers, and at minimum 6 are letters
I need a regex that tests a string for a minimum of 14 characters – valid are A-Za-z0-9#,.-_ minimum of 6 letters within that 14 minimum of 2 numbers within that 14 Is there a way I can wrap this …
Display last date a post was updated on WordPress
I’m using some PHP to display the last time a blog post was updated on WordPress using the get_the_time and get_the_modified_time functions. However, I can’t get the last modified time to display …
PHP – assign value of function to class constant
In PHP when you define a class level constant as in: const MY_CONSTANT = ‘hello constant’; Why can’t you initialize this value with a function such as const MY_FILEPATH = dirname(dirname(__FILE__)) . …
Remove style attribute from HTML tags
I’m not too good with regular expressions, but with PHP I’m wanting to remove the style attribute from HTML tags in a string that’s coming back from TinyMCE. So change <p style=”…”>Text</p> to just vanilla <p>Test</p>. How would I achieve this with s…
Sanitizing HTML input
I’m thinking of adding a rich text editor to allow a non-programmer to change the aspect of text. However, one issue is that it’s possible to distort the layout of a rendered page if the markup is incorrect. What’s a good lightweight way to sanitize html? Answer You will have to decide betwe…
Can I test paypal api’s from localhost
UPDATE 1: According to this tutorial on Using PayPal’s Instant Payment Notification with PHP, PayPal cannot access locally hosted websites unless certain router ports are opened. Is this because the website is about IPN or is this true for all PayPal APIs? ORIGINAL QUESTION: On my laptop, I have a LAMP …