PHP Articles

Page 54 of 81

Get unix timestamp from string without setting default timezone in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 619 Views

In PHP, you can get a Unix timestamp from a string without setting a default timezone by specifying the timezone directly in the string or using DateTime objects. This allows you to work with different timezones without affecting your application's global timezone setting. Getting Default Timezone First, let's check what the default timezone is set to ? UTC Using strtotime() with Timezone in String You can include the timezone directly in the date string when using strtotime() ? Timestamp: 1577862000 Date: 2020-01-01 08:00:00 ...

Read More

Run a Python program from PHP

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 15-Mar-2026 7K+ Views

In PHP, you can execute Python scripts using built-in functions like exec() or shell_exec(). These functions allow you to run Python programs via the shell and capture their output. exec() Function The exec() function executes commands in the shell and optionally captures the output. It returns only the last line of output by default. Syntax exec(string $command, array &$output = null, int &$return_var = null); shell_exec() Function The shell_exec() function is similar to exec() but captures and returns the entire output of the command as a string, instead of just the last ...

Read More

How to effectively hide Href From a Link in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 837 Views

While you cannot completely hide href attributes from a link, there are several PHP techniques to obscure URLs and make them less obvious to users. Here are the most effective methods. Using URL Rewriting Apache's mod_rewrite allows you to create clean URLs that hide the actual file structure ? // .htaccess file RewriteEngine On RewriteRule ^product/([0-9]+)$ /product.php?id=$1 [L] // product.php This transforms product.php?id=5001 into a cleaner product/5001 URL. Using POST Requests with Forms POST requests don't expose parameters in the URL, making them ideal for hiding sensitive data ? ...

Read More

PHP script to get all keys from an array that starts with a certain string

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In PHP, you can filter array keys that start with a specific string using several approaches. Each method offers different advantages depending on your coding style and requirements. Method 1: Using foreach with explode() This method uses explode() to split keys by a delimiter and check the first part ? Array ( [test_val] => 123 [test_result] => 789 ) Method 2: Using array_filter() with strpos() A functional approach using array_filter() with ARRAY_FILTER_USE_KEY flag ? Array ...

Read More

Convert Dashes to CamelCase in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In PHP, converting dashes to camelCase is a common requirement when working with naming conventions. This can be achieved using built-in string functions like ucwords() and str_replace(). Sample input − this-is-a-test-string Sample output − thisIsATestString Method 1: Using ucwords() with Space Replacement This method works by replacing dashes with spaces, capitalizing words, then removing spaces ? thisIsATestString UserProfileData Method 2: Using ucwords() with Delimiter (PHP 5.3+) For PHP version 5.3 and above, ucwords() accepts a delimiter parameter, making the process more efficient ? ...

Read More

How to upload multiple files and store them in a folder with PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 18K+ Views

In PHP, you can upload multiple files simultaneously by creating a file input with array notation and processing each file using the $_FILES superglobal. This approach allows users to select and upload several files in one form submission. HTML Form Setup To enable multiple file uploads, the HTML input must use array notation and the multiple attribute ? Key Requirements Input name must be defined as an array i.e. name="inputName[]" Input element should have multiple="multiple" or just multiple Form must ...

Read More

Extract a property from an array of objects in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 4K+ Views

In PHP, you can extract a specific property from an array of objects using several methods. This is useful when you need to get all values of a particular property from multiple objects. Sample Data Let's start with an array of objects containing ID properties − Array ( [0] => stdClass Object ( [id] => 12 ) ...

Read More

How to identify server IP address in PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 4K+ Views

In PHP, you can identify the server IP address using several built-in superglobals and functions. The method depends on whether your script runs through a web server or as a standalone script. Using $_SERVER Superglobal When running PHP through a web server, use the $_SERVER superglobal to get server information − The output would be − Server IP: 192.168.1.100 Server Port: 80 Using gethostname() and gethostbyname() For PHP version 5.3 and higher, or when running standalone scripts (not through a web server), use these functions − ...

Read More

Can HTML be embedded inside PHP "if" statement?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 6K+ Views

Yes, HTML can be embedded inside PHP ‘if’ statements using several approaches. This allows you to conditionally display HTML content based on PHP logic. Using Alternative Syntax The alternative syntax with colons and endif is clean and readable ? This is displayed if $condition is true Using if-elseif-else Structure For multiple conditions, you can chain elseif and else statements ? Condition met! Another condition met No conditions met ...

Read More

How to detect search engine bots with PHP?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

Search engine bots can be detected in PHP by analyzing the $_SERVER['HTTP_USER_AGENT'] string, which contains information about the client making the request. Bot detection is useful for serving different content or implementing specific behaviors for search engines. Method 1: Using strstr() Function This method checks if a specific bot name exists in the user agent string ? Code explanation − The strtolower() function converts the user agent to lowercase for case-insensitive comparison, then strstr() searches for the bot name within the string. Method 2: Using Regular Expressions A more comprehensive approach ...

Read More
Showing 531–540 of 802 articles
« Prev 1 52 53 54 55 56 81 Next »
Advertisements