Skip to content

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…

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 …

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 …